Comment get my bot vers post a message vers a Microsoft Teams channel?

ayi
Site Admin
Messages : 13176
Inscription : mer. avr. 22, 2026 5:21 pm

Re: Comment get my bot vers post a message vers a Microsoft Teams channel?

Message par ayi »

For anyone who is wondering about the same for c#, here is the solution that worked for me:


    var channelData = context.Activity.GetChannelData<TeamsChannelData>();
var message = Activity.CreateMessageActivity();
message.Text = "Hello World";

var conversationParameters = new ConversationParameters
{
IsGroup = true,
ChannelData = new TeamsChannelData
{
Channel = new ChannelInfo(channelData.Channel.Id),
},
Activity = (Activity) message
};

var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl));
var response = await
connectorClient.Conversations.CreateConversationAsync(conversationParameters);


Note: If you are calling this outside Bot’s controller code then you need to call TrustServiceUrl on serviceUrl as shown here:


    MicrosoftAppCredentials.TrustServiceUrl(serviceUrl, DateTime.MaxValue);
var connectorClient = new ConnectorClient(new Uri(serviceUrl));


Source of answer: https://github.com/OfficeDev/BotBuilder-MicrosoftTeams/issues/162

Répondre

Revenir à « Microsoft Teams »