Forum Discussion
How to get list of channels and members in teams bot
- Oct 09, 2024The TeamsInfo.GetPagedMembersAsync(turnContext) method can be used in various activities, not just in onConversationUpdate. This method is designed to fetch a paginated list of members from a one-on-one, group, or team conversation. It is not limited to being set up in onConversationUpdate.
You can indeed utilize it in the onMessage handler or any other activity handler. When you pass the context received to GetPagedMembersAsync, it will provide the full list of members that are part of the team, not just the members involved in the specific conversation. This method is particularly useful for handling large teams, as it supports pagination to manage the retrieval of members efficiently.
I can use the method you mentioned, but I'm not completely clear on how it operates.
await TeamsInfo.GetPagedMembersAsync(turnContext)
Does this method only work when everything is set up in onConversationUpdate, or can we utilize it in any activity, such as when someone sends a message to the bot
Also, when using this method, can we only retrieve the list of members when users interact with the app and not directly through the API?unlike with resource-specific permissions and Graph API.
Let me know, thanks!
You can indeed utilize it in the onMessage handler or any other activity handler. When you pass the context received to GetPagedMembersAsync, it will provide the full list of members that are part of the team, not just the members involved in the specific conversation. This method is particularly useful for handling large teams, as it supports pagination to manage the retrieval of members efficiently.
- Meghana-MSFTOct 11, 2024Former Employee
yashgandhi - Yes, it only returns the members in that particular conversation.
context.activity.conversation.id is the channel ID, not the team ID. To get the team ID, please refer this
Teams Specific Context for Bot - Teams | Microsoft Learn
- yashgandhiOct 09, 2024Copper Contributor
But actually, when I ran it with onMessage in a 1-to-1 conversation, it only gives me the members of that conversation. So, it returns members list based on the context we pass, such as a group, channel, or DM ? please confirm
My second question is: When we install the app to a team, we receive an ID in context.activity.conversation.id. Is this the channel ID where the user first selected a channel or a teamId? How do I get the team ID of where my app is installed?
Also, we don't need to add any scope for these event listeners to work likeonMessage ? these scopes are provided to all apps by default for them team where app is installed?