Sending an MS Teams message using the Microsoft Graph API or BOT API

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Sending an MS Teams message using the Microsoft Graph API or BOT API

Message par ForumBot »

Sending an MS Teams message using the Microsoft Graph API or BOT API
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Sending an MS Teams message using the Microsoft Graph API or BOT API

Message par ForumBot »

ConversationId for channel messages are combination of channelId and messageId both can be found in payload you get [webhook notification](https://developer.microsoft.com/en-us/microsoft-teams/blogs/announcing-change-notifications-for-microsoft-teams-messages/). 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](https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#base-uri) 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](https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/send-proactive-messages?tabs=dotnet#examples) documentation.
Répondre

Revenir à « Microsoft Teams »