Find out both chat participants in ms teams tab (javascript)

吃可爱长大的小学妹 提交于 2020-01-25 07:52:12

问题


Our applications has relationships between users, and we want to show the relationships in MS teams tabs.

Imagine there's a chat between User A and User B in msteams. User A is currently logged in to ms teams, and adds our app's tab to the chat.

In the tab, we want to show relationship between User A and User B (if it exists). Therefore we need to somehow identify User B (email would be the best).

Through MS teams SDK I can find out chat ID, but not id of User B. I found Graph API route to get members via chat ID: List conversationMembers

Unfortunately, it's in beta. If I understand correctly, it means I cannot use it for production.

Is there other way to find out information (id, email) of User B?

Here is how context looks for tabs (values changed). It's the same both for configuration page and tab itself.

{
  "appSessionId": "0db8663f-35cd-4231-ba3a-a3089b151f8",
  "chatId": "19:15d9c400-6c59-4379-914e-d6d22d1597aa_a883b685-0733-46da-b102-ce7974668cf@unq.gbl.spaces",
  "entityId": "",
  "hostClientType": "desktop",
  "isFullScreen": false,
  "jsonTabUrl": "microsoft-teams-json-tab.azurewebsites.net",
  "locale": "en-us",
  "loginHint": "u1.dabra@outlook.com",
  "ringId": "general",
  "sessionId": "882ef0d4-e222-5ec4-79d9-6911debf550",
  "subEntityId": "",
  "teamSiteDomain": "dabra.sharepoint.com",
  "teamSitePath": "",
  "teamSiteUrl": "",
  "tenantSKU": "free",
  "theme": "default",
  "tid": "9703245a-7156-4221-b92d-ec339ddf183",
  "upn": "myemail@outlook.com",
  "userLicenseType": "Unknown",
  "userObjectId": "a883b685-0733-46da-b102-ce797466c7",
  "userPrincipalName": "admin@Dabra.onmicrosoft.com"
}

Upd: I was not able to solve my problem yet, but I've found way to get chat users inside the bot when installing tab. Maybe this code will be useful to someone.

Response is the list of chat users we are looking for.

this.onTeamsMembersAddedEvent(async (teamMembersAdded, teamInfo, turnContext, next) => {
    const connector = turnContext.adapter.createConnectorClient(turnContext.activity.serviceUrl);
    const conversationId = turnContext.activity.conversation.id;
    const response = await connector.conversations.getConversationMembers(conversationId);
// Response is the list of users in chat
console.log(response);
      await next();
    });

回答1:


There's a way to get all the members of the current conversation using the TurnContext.Conversation.GetConversationMembersAsync method, if you're using a Bot, written in C# (I'm sure there's an equivalent for a Bot in Node.js). What this means is that, if you add a Bot to your application as well as the existing Tab, you can query for the conversation members when the Bot is added to the group chat. When the Bot is added to the conversation, it receive a OnMembersAddedAsync event, where you could do the "GetConversationMembersAsync" call, something like this:

protected override Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{

            List<ChannelAccount> teamMembers = (await turnContext.TurnState.Get<IConnectorClient>().Conversations.GetConversationMembersAsync(
                turnContext.Activity.GetChannelData<TeamsChannelData>().Team.Id).ConfigureAwait(false)).ToList();

            List<MicrosoftTeamUser> teamsUsers = new List<MicrosoftTeamsUser>();
            foreach (var item in teamMembers)
            {
                var teamsUser = JsonConvert.DeserializeObject<MicrosoftTeamUser>(item.Properties.ToString());
                teamsUser.Id = item.Id;
                teamsUsers.Add(teamsUser);
            }
}

You'll need a definition for MicrosoftTeamsUser, as follows:

public class MicrosoftTeamsUser
{
    public string Id { get; set; }

    public string ObjectId { get; set; }

    public string GivenName { get; set; }

    public string Surname { get; set; }

    public string Email { get; set; }

    public string UserPrincipalName { get; set; }

    public string TenantId { get; set; }
}


来源:https://stackoverflow.com/questions/59598946/find-out-both-chat-participants-in-ms-teams-tab-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!