botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

[Question] What is the recommended approach to get list of all users?

Open v46 opened this issue 9 years ago • 5 comments

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!

v46 avatar Jun 21 '17 04:06 v46

For Teams you can use the SDK provided here on:

  • NuGet for C#: https://www.nuget.org/packages/Microsoft.Bot.Connector.Teams
  • npm for Node.js: https://www.npmjs.com/package/botbuilder-teams

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

Sample code (Node.js):

var conversationId = session.message.address.conversation.id;
  connector.fetchMemberList(
    (<builder.IChatConnectorAddress>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#):

// 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!

nrobert avatar Jun 22 '17 12:06 nrobert

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

stevengum avatar Jun 22 '17 16:06 stevengum

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?

v46 avatar Jun 22 '17 18:06 v46

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?

nrobert avatar Jun 22 '17 19:06 nrobert

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.

stevengum avatar Jun 23 '17 21:06 stevengum