Search code examples
botframework

Identifying "Owner" in Bot Framework for Ms Teams (TeamsChannelAccount UserRole property only ever says "user")


I have written an Ms Teams Bot using the Bot Framework with .Net and I would like to identify the Owner of the Team in which the Bot is installed (e.g. to send them an adaptive card with more privileged features on it, rather than having the whole team see it).

the V4.9 release note of the bot framework states:

The TeamsChannelAccount object has been updated to include userRole (one of owner, member, or guest) and tenantId (for the user's tenantId)

Yet this seems to be incorrect. When using TeamsInfo.GetMemberAsync or TeamsInfo.GetPagedMembersAsync to retrieve member info (which all return the TeamsChannelAccount object mentioned above) the UserRole property only ever shows "user" as the value - never "owner" or otherwise.

How can I identify the owner of the team? Thank you.


Solution

  • You could instead try to use MSGraph APIs to identify the Owner of a Group. Assuming you have the requisite permissions, you can make a GET call to the appropriate Graph endpoint and it will return to you the owner's ID and name, among other things. You could then use the ID to identify the owner in Teams. MSGraph API calls for getting members also have a roles field, and that can have owner in it as well.

    If this solution could work for you, the Teams Auth sample is a good place to start.

    Here are some potentially helpful docs pages as well: