For context, please read this question, especially edit 3, along with the answer to edit 3.
I'm trying to get my Teams bot to get access to a list of participants in a private 1:1 conversation between two people (me and anyone else having a conversation with me), by invoking a messaging extension. Can this be done at all?
I'm using the latest Bot Builder SDK (4.6.3 at the time of writing)
A messaging extension query is handled by OnTeamsMessagingExtensionQueryAsync
method, which provides ITurnContext<IInvokeActivity>
object, which allows me to access the current conversation object using turnContext.Activity.Conversation
property. This conversation object has an Id which looks like this:
a:15ya3x9GGFwBZUxa5Kd8DZzJ3IaWypTbCYjRhRL6bRYb0NmG4flXunysvJZWKdrJi3QVRrG7xZcjmZ9csxzyoK5cXuJb0hq29EpONRk6gLE7vprBPsA3jLTKymSTCdAqp
Let's assume I have authenticated with the bot and that I've consented to these API permissions:
- Chat.ReadWrite
- User.Read
- User.ReadBasic.All
- openid
- profile
I have a valid access token which I've obtained by calling
await botAdapter.GetAadTokensAsync(
turnContext,
oauthConnectionName, // the connection name as configured in the bot channel registration
new string[] { "https://graph.microsoft.com" },
turnContext.Activity.From.Id, // the Teams Id of the action invoker, a.k.a me
cancellationToken);
Now when I call the Graph API endpoint, suggested by the linked answer, using the conversation Id above, I get an error 400 - bad request. With error description "Bad Request". Nothing more. In this case, the call would look like this:
https://graph.microsoft.com/beta/chats/a:15ya3x9GGFwBZUxa5Kd8DZzJ3IaWypTbCYjRhRL6bRYb0NmG4flXunysvJZWKdrJi3QVRrG7xZcjmZ9csxzyoK5cXuJb0hq29EpONRk6gLE7vprBPsA3jLTKymSTCdAqp/members
The Graph Explorer confirms the same - code "BadRequest", message "Bad Request".
Now when I called https://graph.microsoft.com/beta/me/chats
, I have noticed that chat IDs look nothing like above. After an investigation, I found that the actual ID of the target conversation, as communicated by the Graph API, was
19:62177c5c-7a61-44a5-9772-8d193a7f433f_71840467-a52d-4aaa-b15b-6fc89bd93a9b@unq.gbl.spaces
So when the following call would be invoked: https://graph.microsoft.com/beta/chats/19:62177c5c-7a61-44a5-9772-8d193a7f433f_71840467-a52d-4aaa-b15b-6fc89bd93a9b@unq.gbl.spaces/members
, I was able to obtain a list of conversation members.
So what's the correlation between the ID given by turnContext.Activity.Conversation.Id
and the actual Id expected by the Graph API? I'd like to note that, as observed in this example, it's obvious the expected ID already contains IDs of conversation members without the need to call this API, with the format <some-id>:<convo-member-id>_<my-id>@unq.gbl.spaces