Search code examples
c#azurebotframeworkbots

Get MS Teams Channel Conversation ID


I'm currently creating an Azure QnA-bot that can send a message from the webchat to Teams and from Teams back to the webchat.

Everything works fine so far but some of the information I'm using has to be set trough some detours.

This Teams Conversation ID for example:

private string teamsThread = "19:[email protected]";

The way I find out about this, would be to install the bot on a Teams Channel. Then message the bot in the Teams Channel like @myBot anyMessage and it would answer me because I have this in Code:

await turnContext.SendActivityAsync(MessageFactory.Text("Conversation.Id: " + turnContext.Activity.Conversation.Id.ToString()), cancellationToken);

And this is how I did find out about the Teams Channel_ConversationID.

Is there a way to get the Conversation ID by just installing the bot on the Channel?

Like: Install Bot to Channel -> Save Conversation ID "19:[email protected]" in Azure Cosmos Table

Instead of: Install Bot -> Write message to the bot in Teams -> Save Conversation ID in Azure Cosmos Table


Solution

  • A conversation ID is generated as soon as you install the bot to the Team and you can capture it in OnTurnAsync().

    Using App Studio, I got my bot to this part of the install process (after selecting the team and just before selecting the channel to install to):

    enter image description here

    And I got this in OnTurnAsync:

    enter image description here

    It also falls through to OnConversationUpdateActivityAsync().

    However, it can only converse in the General channel because that's what the conversation ID is tied to upon install. NO activities are fired when installed to a non-General channel within a Team.

    Additionally, the activities fired when installed to a Team are only fired once per App Registration App ID, EVER. If you want to test this again, you need an entirely new app registration.

    So to answer your question, "yes, if you want the Conversation ID for the General Channel," but "no, if you want the Conversation ID for any other channel".