Botframework-sdk: [Question] What is the recommended approach to get list of all users?

Created on 21 Jun 2017  路  5Comments  路  Source: microsoft/botframework-sdk

I am trying to get a list of all users for given channel - primarily MS Teams and Skype. Does the Bot framework provide such an API similar to Slack? (there was mention of this coming to the SDK).

We are on the Node SDK. Appreciate the help!

customer-replied-to

Most helpful comment

For Teams you can use the SDK provided here on:

As depicted on the documentation (here), you can get the list of team members.

Sample code (Node.js):
```Node.js
var conversationId = session.message.address.conversation.id;
connector.fetchMemberList(
(session.message.address).serviceUrl,
conversationId,
teams.TeamsMessage.getTenantId(session.message),
(err, result) => {
if (err) {
session.endDialog('There is some error');
}
else {
session.endDialog('%s', JSON.stringify(result));
}
}
);

Sample code (C#):
```C#
// Fetch the members in the current conversation
var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
var members = await connector.Conversations.GetTeamsConversationMembersAsync(activity.Conversation.Id, activity.GetTenantId());

// Concatenate information about all the members into a string
var sb = new StringBuilder();
foreach (var member in members)
{
    sb.AppendFormat(
        "GivenName = {0}, Surname = {1}, Email = {2}, UserPrincipalName = {3}, AADObjectId = {4}, TeamsMemberId = {5}",
        member.GivenName, member.Surname, member.Email, member.UserPrincipalName, member.ObjectId, member.Id);

    sb.AppendLine();
}

// Post the member info back into the conversation
await context.PostAsync($"People in this conversation: {sb.ToString()}");

But it is not listing every user of MS Teams. If you try to do proactive messaging by getting user id (in the following format "id": "29:1GcS4EyB_oSI8A88XmWBN7NJFyMqe3QGnJdgLfFGkJnVelzRGos0bPbpsfJjcbAD22bmKc4GMbrY2g4JDrrA8vM06X1-cHHle4zOE6U4ttcc"), you have to find another way. If you find this way, please share it!

All 5 comments

For Teams you can use the SDK provided here on:

As depicted on the documentation (here), you can get the list of team members.

Sample code (Node.js):
```Node.js
var conversationId = session.message.address.conversation.id;
connector.fetchMemberList(
(session.message.address).serviceUrl,
conversationId,
teams.TeamsMessage.getTenantId(session.message),
(err, result) => {
if (err) {
session.endDialog('There is some error');
}
else {
session.endDialog('%s', JSON.stringify(result));
}
}
);

Sample code (C#):
```C#
// Fetch the members in the current conversation
var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
var members = await connector.Conversations.GetTeamsConversationMembersAsync(activity.Conversation.Id, activity.GetTenantId());

// Concatenate information about all the members into a string
var sb = new StringBuilder();
foreach (var member in members)
{
    sb.AppendFormat(
        "GivenName = {0}, Surname = {1}, Email = {2}, UserPrincipalName = {3}, AADObjectId = {4}, TeamsMemberId = {5}",
        member.GivenName, member.Surname, member.Email, member.UserPrincipalName, member.ObjectId, member.Id);

    sb.AppendLine();
}

// Post the member info back into the conversation
await context.PostAsync($"People in this conversation: {sb.ToString()}");

But it is not listing every user of MS Teams. If you try to do proactive messaging by getting user id (in the following format "id": "29:1GcS4EyB_oSI8A88XmWBN7NJFyMqe3QGnJdgLfFGkJnVelzRGos0bPbpsfJjcbAD22bmKc4GMbrY2g4JDrrA8vM06X1-cHHle4zOE6U4ttcc"), you have to find another way. If you find this way, please share it!

@v46, did @nrobert's answer help you?

Yes, Thank you @nrobert. Looks promising, going to try this approach and will report here if there are issues.

I didn't follow your note on the proactive messaging. We have had success with proactive messaging in general. Are you referring to something related to using it along side pulling the user list?

I was talking about sending a message to someone who never talked to your bot before. Did you had success with that with Skype or MS Teams?

Since the original question was answered, I'm closing this issue for now. If there are any questions or comments please open a new issue with your specific scenario and add a reference to this issue.

Was this page helpful?
0 / 5 - 0 ratings