Search code examples
botframeworkmicrosoft-graph-apimicrosoft-teams

Getting graph-compatible Team and conversation IDs in a Teams bot


I'm trying to use the new message action feature in Teams in my bot application. I can get the task module to invoke, but I want to have the bot read the contents of the full message thread (not just the first message as passed into the context). When I examine the ChannelData though, I get this:

ChannelData {{
  "channel": {
    "id": "19:[email protected]"
  },
  "team": {
    "id": "19:[email protected]"
  },
  "tenant": {
    "id": "8c6ae172-a3ea-4f50-994d-a0256822697f"
  },
  "source": {
    "name": "compose"
  }
}}

It looks like you should be able to get the messages in a channel using the beta API like this:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var replies = await graphClient.Teams["303d2c1c-f1c5-40ce-b68e-544343d7f42b"].Channels["19:[email protected]"].Messages["1555375673184"].Replies
    .Request()
    .GetAsync();

The challenge is, calling this using a TeamID, formatted as "19:[email protected]" doesn't work, and instead it needs the TeamID specified as a standard GUID (in this case, d12f244e-fd24-4430-a58a-1b2650ba8997). Is there a way to convert between these two ID formats? Is there something that details why they're different?


Solution

  • You can!

    You have to use the Microsoft.Bot.Builder.Teams Package / GitHub.

    From the README, you can get the Team ID:

    var teamInfo = await teamsContext.Operations.FetchTeamDetailsAsync(incomingTeamId);
    

    That will be in teamInfo.AadGroupId and is formatted as the GUID.