Forum Discussion

yashgandhi's avatar
yashgandhi
Copper Contributor
Oct 03, 2024

How to get list of channels and members in teams bot

 

Hi,

I’m working on building a Microsoft Teams bot and came across the TeamsInfo.getTeamChannels(turnContext, teamId) method in the BotBuilder SDK. Could you help clarify how it works? Specifically, how does turnContext return data for a team? I’ve already assigned all the necessary scopes through the Teams Developer Portal. Do I still need to use Microsoft Graph APIs, or will this method handle everything?

Also, when calling this method, I noticed that one channel (the "General" channel) is missing from the response. What’s the best way to fetch a complete list of members and channels in a team where my bot is installed, especially since users are interacting with it in personal DMs?

 

 

 

 

[
  {
    "name": undefined,
    "id": "19:nGtWIyKBcs0m93LgdScfymNX4_YhoaEj0Zo1@thread.tacv2"
  },
  {
    "name": "newchannel",
    "id": "19:42baf94a1a3e86cb0@thread.tacv2"
  },
  {
    "name": "testchannel",
    "id": "19:54b4ac2af6228c4573fff12@thread.tacv2"
  }
]

  • The 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.

Resources