How to get a list of all the members from MS Teams organization using Bot Framework Connection

Viewed 221

I am developing a bot for MS Teams using JavaScript.

Using Bot Framework Connector I have installed the bot into one Team, storing teamId, tenantId, serviceUrl and channelId. I was able to send a message into the channel and also a direct message to an user, knowing its userId.

My question is how to get a list of all the users from the MS Teams organization or at least how to get an user ID knowing its email and UPN? It is this possible, having only this information, to do that using botframework-connector?

Note: I need to mention that I can't use Graph API since my bot doesn't have Graph Permissions and I don't have a context, my bot is initiating the conversation.

1 Answers

I am developing a bot for MS Teams using JavaScript.

Using Bot Framework Connector I have installed the bot into one Team, storing teamId, tenantId, serviceUrl and channelId. I was able to send a message into the channel and also a direct message to an user, knowing its userId.

My question is how to get a list of all the users from the MS Teams organization

Without Graph, you're not going to be able to get all users from the org. Channel possibly, not sure.

or at least how to get an user ID knowing its email and UPN? It is this possible, having only this information, to do that using botframework-connector?

Using the TeamsActivityHandler, you can get the context of a user in the turn they are messaging. There is a handful of information about the user. Such as:

AadObjectId: <REDACTED>
Email: <REDACTED>
GivenName: null
Id: <REDACTED>
Name: <REDACTED>
Properties: {{}}
Role: null
Surname: null
TenantId: <REDACTED>
UserPrincipalName: <REDACTED>
UserRole: "guest"

See this sample, and this line for more information/examples.

Note: I need to mention that I can't use Graph API since my bot doesn't have Graph Permissions and I don't have a context, my bot is initiating the conversation.

Without Graph access, you're not going to be able to get a lot more than that unfortunately.

Related