1
votes

I'm trying to implement the following solution: a web application that subscribes to all MS teams chat messages. If a message contains forbidden text, the application should somehow warn the user (Ideally by replying to the same message, or, if not possible, initiate a conversation with the user).

I'm able to receive all chat webhooks and process them, but I could not find any way to post a message back to the Teams channel using the Graph API (the operation described in https://docs.microsoft.com/en-us/graph/api/channel-post-messagereply?view=graph-rest-beta&tabs=http
is not supported for Application permissions - only delegated ones which isn't suitable for our case).

So I'm trying to send proactive messages using the Bot framework, However, the bot framework requires a teams conversation ID which I don't have (the graph API webhook provides the team, channel and user IDs, none of which are accepted by the Bot API).

Does anyone know of a way I can retrieve the teams conversation ID using the team ID and channel ID provided by the graph API?

Thanks, Dan

1

1 Answers

0
votes

ConversationId for channel messages are combination of channelId and messageId both can be found in payload you get webhook notification. You can reply to existing conversation by using following by building converstionId like this:

 conversationId =   $"{channelId};messageid={messageId}"

For reply to work, your Bot needs to installed in the team and should have serviceURL saved at some place to refer back. Here is sample code which show how you can reply to existing message.

var serviceURL = "YOUR Service URL- You get this in each bot payload";
MicrosoftAppCredentials.TrustServiceUrl(serviceURL, DateTime.MaxValue);
using var connector = new ConnectorClient(new Uri(serviceURL, MicrosoftAppId, MicrosoftAppPassword);


var conversationId = $"{channelId};messageid={messageId}";
var replyActivity = MessageFactory.Text($"This is simple reply to existing conversation.");
replyActivity.Conversation = new ConversationAccount(id: conversationId);
var response = await connector.Conversations.SendToConversationAsync(conversationId, replyActivity);

For 1:1 reply- please take a look at Sending Proactive Message documentation.