简体   繁体   English

在个人范围(MS Teams)中安装机器人时如何获取团队ID?

[英]How to get team id when the bot is installed in personal scope(MS Teams)?

I have a use case where I need to show following information in my personal application.我有一个用例,我需要在我的个人应用程序中显示以下信息。

  1. List of channels in teams where bot is installed.安装机器人的团队中的频道列表。
  2. List of users in teams where bot is installed.安装了 bot 的团队中的用户列表。

I was exploring connector client for the same and came up with following code:-我正在探索相同的连接器客户端并提出以下代码:-

   const credentials = new MicrosoftAppCredentials(appId, appPassword);
   const connectorClient = new ConnectorClient(credentials, {
        baseUri: serviceUrl
    });
   const token = await credentials.getToken();
   axios.defaults.headers.common.Authorization = `Bearer ${ token }`;

   # To get channels
   const response = await axios.get(
        'https://smba.trafficmanager.net/in/v3/teams/{teamId}/conversations'
    );

    # To get members
   const users = await connectorClient.conversations.getConversationPagedMembers(teamId);

This works perfect as long as I have the teamId.只要我有 teamId,这就完美了。

But the issue I am facing here is with respect to finding teamId in personal scope.但我在这里面临的问题是在个人范围内查找teamId I install my bot application as follows by choosing the Add option.我通过选择“添加”选项来安装我的机器人应用程序,如下所示。

在此处输入图片说明

As far as I understand, the above installs the bot in the personal scope of the user.据我了解,以上将机器人安装在用户的个人范围内。 Now, in this scenario the team id information is not present in conversationUpdate event at all.现在,在这种情况下, conversationUpdate事件中根本不存在团队 ID 信息。 Please note that this is the first time I am installing the bot in the team, so the data should be available as per Microsoft documentation, but the only information available in channel object is tenant.请注意,这是我第一次在团队中安装机器人,因此根据 Microsoft 文档,数据应该可用,但通道对象中唯一可用的信息是租户。

{
    "membersAdded": [
        {
            "id": "28:f5d48856-5b42-41a0-8c3a-c5f944b679b0"
        }
    ],
    "type": "conversationUpdate",
    "timestamp": "2017-02-23T19:38:35.312Z",
    "localTimestamp": "2017-02-23T12:38:35.312-07:00",
    "id": "f:5f85c2ad",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/amer-client-ss.msg/",
    "from": {
        "id": "29:1I9Is_Sx0OIy2rQ7Xz1lcaPKlO9eqmBRTBuW6XzkFtcjqxTjPaCMij8BVMdBcL9L_RwWNJyAHFQb0TRzXgyQvA"
    },
    "conversation": {
        "isGroup": true,
        "conversationType": "channel",
        "id": "19:efa9296d959346209fea44151c742e73@thread.skype"
    },
    "recipient": {
        "id": "28:f5d48856-5b42-41a0-8c3a-c5f944b679b0",
        "name": "SongsuggesterBot"
    },
    "channelData": {
        // for me this object is empty
        "team": {
            "id": "19:efa9296d959346209fea44151c742e73@thread.skype"
        },
        "eventType": "teamMemberAdded",
        "tenant": {
            "id": "72f988bf-86f1-41af-91ab-2d7cd011db47"
        }
    }
}

Next, I also tried to install the bot in the team scope by using Add To Teams option.接下来,我还尝试使用“添加到团队”选项在团队范围内安装机器人。 In this case it prompts me to select a channel to install, in which I choose general .在这种情况下,它会提示我选择要安装的频道,我在其中选择了general

在此处输入图片说明

Now, I do get the team object inside channelData in onConversationUpdate and this flow works perfectly fine.现在,我得到球队的内线对象channelDataonConversationUpdate并且此流程运行完美。

{
    "membersAdded": [
        {
            "id": "28:64564f44-dd7c-441a-b427-efcd662f21b5"
        }
    ],
    "type": "conversationUpdate",
    "timestamp": "2021-10-14T13:22:01.6072361Z",
    "id": "f:4ebc9a41-5140-7621-33f5-31d97275ce00",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/in/",
    "from": {
        "id": "29:17ZGff4Pvqz_zSNqEexg-86uBFcB6vnOBZzCwu4_puGdDsrYWCW_DdlB15PrcjC--nLlqD5CwtLMJyzXPY5OSsg",
        "aadObjectId": "eac26e98-104a-4785-87aa-bcf77ea1d7c1"
    },
    "conversation": {
        "isGroup": true,
        "conversationType": "channel",
        "tenantId": "c8fef0de-e240-4456-b523-3285ecc62087",
        "id": "19:y7qDBfGH2jE_Ze6G8mJS_CiWiqCaRFfH77jFZvJ1xgU1@thread.tacv2"
    },
    "recipient": {
        "id": "28:64564f44-dd7c-441a-b427-efcd662f21b5",
        "name": "Trick"
    },
    "channelData": {
        "team": {
            "aadGroupId": "5bc77aa9-9487-49ae-958f-b37b2191e64d",
            "name": "test 5",
            "id": "19:y7qDBfGH2jE_Ze6G8mJS_CiWiqCaRFfH77jFZvJ1xgU1@thread.tacv2"
        },
        "eventType": "teamMemberAdded",
        "tenant": {
            "id": "c8fef0de-e240-4456-b523-3285ecc62087"
        }
    }
}

So what I am trying to understand here is that, why is the information not coming in case the bot is installed in personal scope?所以我在这里想理解的是,如果机器人安装在个人范围内,为什么信息不会出现?

I am asking this mainly because without personal scope added for bot(ie if I keep scope only as team ), the application does not show for user, inside Apps.我问这个主要是因为没有为 bot 添加个人范围(即如果我只将范围保留为team ),应用程序不会在应用程序内部向用户显示。 But if I allow the scope to be extended to personal the user might select that while installing the application and my teamId information will not be available to fetch the data, that I need.但是,如果我允许将范围扩展到personal则用户可能会在安装应用程序时选择该范围,并且我的teamId信息将无法用于获取我需要的数据。

This brings to my next question, which is, is there any way in which the default add button on the add app screen installs the bot in such a way that I get team object inside channelData , in conversationUpdate in every scenario, ie whether I choose add or add to team?这使我的下一个问题,那就是,有没有在其中默认的任何add的按钮add app屏幕安装在这样的机器人,我得到team内部对象channelData ,在conversationUpdate在每一个场景,即无论我选择添加或添加到团队?

Is this how it is supposed to behave or am I missing something.这是它应该如何表现还是我错过了什么。 Would love to hear some thoughts on this.很想听听对此的一些想法。 Thanks in advance.提前致谢。

It might be that you're over thinking this - here's a more simple view:可能是你想多了——这里有一个更简单的观点:

  1. if you install a bot into a Team , you'll get a Team Id (and any related channel where it is installed).如果您将机器人安装到Team 中,您将获得一个 Team Id(以及安装它的任何相关频道)。

  2. if you have "personal" scope set up for the bot, then the user also has the option to install the bot into "personal" scope.如果您为机器人设置了“个人”范围,那么用户可以选择将机器人安装到“个人”范围中。 As this implies, they are NOT installing the bot INTO an actual Team - that's why you're not receiving a Team Id.这意味着,他们没有将机器人安装到实际的团队中 - 这就是您没有收到团队 ID 的原因。 It's not broken - it's entirely correct.它没有坏掉 - 这是完全正确的。

If you don't WANT your bot to be able to be installed in personal scope, simply remove that option in your manifest (the "personal" scope) - you have the ability to choose because it depends what you're wanting the user to be able to do with your bot.如果您不希望您的机器人能够安装在个人范围内,只需在您的清单(“个人”范围)中删除该选项 - 您可以选择,因为这取决于您希望用户做什么能够用你的机器人做。 Some bots only make sense inside a Team, others only in Personal Scope, others only in Group Chat or in a Meeting - you can allow your bot to installed in any/all of these are relevant.一些机器人只在团队内部有意义,其他只在个人范围内有意义,其他只在群聊或会议中 - 您可以允许您的机器人安装在任何/所有这些相关的地方。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MS Teams - 获取安装机器人的团队 ID 和频道 ID - MS Teams - fetch the team Ids and channel Ids in which the bot is installed bot框架和Microsoft团队-如何获得与团队相关的所有渠道? - bot framework and Microsoft teams - how to get all channels associated to a team? 每当用户卸载 bot 并且仅在个人范围内安装 bot 时,有没有办法获取用户详细信息? - Is there any way to get user details whenever user uninstalls bot and bot is installed in personal scope only? 以编程方式将机器人 (ms-botbuilder) 添加到 MS Teams 团队/频道 - Add bot (ms-botbuilder) to the MS Teams Team/Channel programmatically 如何让机器人在将其引导到 MS Teams 时接收附件 - How to make a bot receive attachments when channeling it to MS Teams ms team bot的conversation.id是独一无二的吗? - is conversation.id for ms teams bot unique? 错误:此方法仅在msteams团队范围内有效 - Error:This method is only valid within the scope of ms teams team 如何通过 ms 团队应用程序中的自适应卡发送团队 ID 和频道 ID - How can send Team ID and Channel id through adaptive card from ms teams app 如何在安装在不同组织的 MS Teams Bot 中接收用户照片? - How to receive user photos in MS Teams Bot which installed in different organizations? 如何获取已发送消息 Bot Framework(团队频道)的消息 ID? - How to get message id of sent message Bot Framework (Teams channel)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM