在ms小组标签中找到两个聊天参与者(JavaScript) [英] Find out both chat participants in ms teams tab (javascript)

查看:112
本文介绍了在ms小组标签中找到两个聊天参与者(JavaScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序具有用户之间的关系,我们希望在MS团队标签中显示这些关系.

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

想象一下,用户A和用户B之间在msteams中进行了聊天. 用户A当前已登录ms团队,并将我们应用程序的标签添加到聊天中.

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.

在选项卡中,我们想要显示用户A和用户B之间的关系(如果存在).因此,我们需要以某种方式识别用户B(最好是电子邮件).

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).

通过MS团队SDK,我可以找到聊天ID,但不能找到用户B的ID. 我发现了通过聊天ID获取成员的Graph API路由:

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.

还有其他方法可以查找用户B的信息(id,电子邮件)吗?

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"
}

更新: 我还无法解决问题,但是我已经找到了在安装Tab时将聊天用户吸引到机器人内部的方法.也许这段代码对某人有用.

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();
    });

推荐答案

如果使用的是Bot,则可以使用TurnContext.Conversation.GetConversationMembersAsync方法来获取当前对话的所有成员,该方法是用C#编写的(我确定Node.js中的Bot等效.这意味着,如果将Bot添加到应用程序以及现有的Tab,则可以在Bot添加到群聊中时查询对话成员.将Bot 添加到对话中后,它会收到一个OnMember LeicesterAsync事件,您可以在其中执行"GetConversationMembersAsync"调用,如下所示:

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);
            }
}

您需要为MicrosoftTeamsUser定义,如下所示:

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; }
}

这篇关于在ms小组标签中找到两个聊天参与者(JavaScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆