TeamsBot-如何从对话更新事件中获取团队ID? [英] TeamsBot - How do I get the Team Id from a conversationupdate event?

查看:59
本文介绍了TeamsBot-如何从对话更新事件中获取团队ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在安装Teams机器人并将其添加到团队中.当我将其添加到团队时,在初始通话中,我会收到"conversationUpdate"消息.事件正确,在OnTurnAsync中.我遇到的问题是,任何获取团队本身的调用都失败了,因为我看不到要获取ID来获取团队数据的任何内容.

I'm installing a Teams bot and adding it to a team. When I add it to the team, on the initial call I get the "conversationUpdate" event correctly, in OnTurnAsync. The issue I'm running into is that any call to get the team itself is failing because there is nothing there, that I can see, for getting the Id to call to get the team data.

我希望能够将其添加到团队中,获取该事件,然后获取与其添加到的团队相关的数据.

I want to be able to add it to the team, get that event and then get the data related to the team it was added to.

这是我正在尝试的.

        private const string ActOnType = "conversationUpdate";

        public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default)
        {
            if (IsConversationUpdate(turnContext))
            {
                // This fails because TeamsGetInfo is returning null
                var teamDetails = await TeamsInfo.GetTeamDetailsAsync(turnContext,  turnContext.Activity.TeamsGetTeamInfo().Id, cancellationToken);
            }
        }

        private bool IsConversationUpdate(ITurnContext turnContext) => string.Equals(turnContext.Activity.Type,
            ActOnType, StringComparison.InvariantCultureIgnoreCase);

其他说明...
turnContext.Activity.TeamsGetChannelId()为null,ChannelData也为null.还有更多电话需要渠道数据,但是最初将机器人添加到团队的电话没有任何数据.

Other notes...
turnContext.Activity.TeamsGetChannelId() is null, as is ChannelData. Any further calls have the channel data, but the initial one where I add the bot to the team does not have any.

从通话中添加我的JSON

Adding my JSON from the call

{
    "membersAdded": [
        {
            "id": "29:1HqtPeQvYpNL682R_NeBMndg6kYbZbBHsZliZdAT2xWsJWzS0_b50S1ijo2hmPu5i0HTrvqPiOBxqpbtJjS7zyja",
            "aadObjectId": "{valid guid}"
        },
        {
            "id": "28:{valid guid}"
        }
    ],
    "type": "conversationUpdate",
    "timestamp": "2021-01-11T18:15:49.9118003Z",
    "id": "f:{valid guid}",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/amer/",
    "from": {
        "id": "29:1HqtPeQvYpNL682R_NeBMndg6kXaZbBHsZliZdAT2xWsJWzS0_gOS1ijo2hmPu5i0HTrvqPiOBxqpbtJjS6zyjA",
        "aadObjectId": "{valid guid}"
    },
    "conversation": {
        "conversationType": "personal",
        "tenantId": "{valid guid}",
        "id": "a:1UgWdBcfpF4JUtOCCjQZsvhjl-QK9YBBnALG7ACgA0QdKx_xGICsQ3d6l94t_pPed7fvtnwSnRlYcWe7kXT7dStP-YCtuvliI8GPZj9Sd5P2wHsBAAn1ibwdad4Lq-O3B"
    },
    "recipient": {
        "id": "28:{valid guid}",
        "name": "LocalBot"
    },
    "channelData": {
        "tenant": {
            "id": "{valid guid}"
        }
    }
}  

推荐答案

我将在这里发布答案,以防有人进入...

I'll post the answer here in case anyone comes into it...

该机器人被添加到团队后,您只能获得一次此事件.如果错过了,您将不再获得数据.卸载并重新安装漫游器不会再次触发该事件.如果仍然无法使用它,建议采取的措施是从Azure删除该应用程序,然后使用相同的名称重新进行处理.

You can only get this event once for when the bot was added to the team. If you miss it, you no longer get the data. Uninstalling and reinstalling the bot will not fire the event again. If you're still not getting it, the recommended action was to remove the app from Azure and re-do it with the same name.

请参见 github讨论

在我们的场景中,我认为对此的限制不在我认为可行的解决方案范围之内,因此我决定走另一条路来获取团队数据.由于数据是在此事件之后的事件中传递的,因此我将其抓取并做我需要做的事情.

In our scenario, I decided that the limitations on this were not within the realm of what I considered a working solution and I decided to go down a different route for getting the team data. Since the data was coming through in events after this one, I grab it then and do what I need to do with it.

这篇关于TeamsBot-如何从对话更新事件中获取团队ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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