【问题标题】:Get AADObject Id of the user @mentioned to the Microsoft Teams Bot获取向 Microsoft Teams Bot 提及的用户的 AADObject Id
【发布时间】:2020-03-19 17:18:32
【问题描述】:

我正在使用 Azure Bot 服务开发 Microsoft Teams 机器人,我有一个用例,我需要获取@提到的用户 AAD 对象 ID 并使用此 ID 来获取其他企业特定的用户信息。 我曾尝试使用turnContext 对象的GetMentions() API,它返回Channel Account 对象,但是,通道帐户的AAD 对象属性为空,尽管它有一个我认为对应于Bot Service channel's (Microsoft Teams) 用户的Id 属性。

根据我的研究,有人可以告诉我如何获取用户 AAD 对象 ID 或指向正确的文档吗?

【问题讨论】:

    标签: azure botframework microsoft-teams azure-bot-service microsoft-graph-teams


    【解决方案1】:

    您可以使用从 GetMentions(29:id) 收到的 id 使用 Bot Context 获取用户的 id。请尝试此代码,如果您遇到任何问题,请告诉我们:

      private static async Task<string> GetUserEmailId(Activity activity, string id)
        {
            var teamId = context.Activity.GetChannelData<TeamsChannelData>().Team.Id;
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
            var members1 = await connector.Conversations.GetConversationMembersAsync(teamId);
            var mem = members1.Where(m => m.Id == id).First().AsTeamsChannelAccount().ObjectId;
            return mem;
        }
    

    【讨论】:

    • 嗨 Gousia,这是一个很好的线索,但是,它对我有用,相反我使用了这个 var members = await TeamsInfo.GetMembersAsync(turnContext, cancelToken);
    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 2020-09-05
    • 1970-01-01
    • 2023-03-11
    • 2017-11-05
    • 1970-01-01
    • 2020-07-21
    • 2020-12-17
    相关资源
    最近更新 更多