获取向 Microsoft Teams Bot 提及的用户的 AADObject Id
Get AADObject Id of the user @mentioned to the Microsoft Teams Bot
我正在使用 Azure Bot 服务开发 Microsoft Teams 机器人,我有一个用例,我需要获取 @mentioned 用户 AAD 对象 ID 并使用此 ID 获取其他企业特定的用户信息。
我尝试使用 turnContext 对象的 GetMentions()
API 哪个 returns Channel Account object, however, the AAD Object property of channel account is empty, though it has an Id property which I believe corresponds to the Bot Service channel's (Microsoft Teams) 用户。
根据我的研究,有人可以告诉我如何获取用户 AAD 对象 ID 或指向正确的文档吗?
您可以使用从 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;
}
我正在使用 Azure Bot 服务开发 Microsoft Teams 机器人,我有一个用例,我需要获取 @mentioned 用户 AAD 对象 ID 并使用此 ID 获取其他企业特定的用户信息。
我尝试使用 turnContext 对象的 GetMentions()
API 哪个 returns Channel Account object, however, the AAD Object property of channel account is empty, though it has an Id property which I believe corresponds to the Bot Service channel's (Microsoft Teams) 用户。
根据我的研究,有人可以告诉我如何获取用户 AAD 对象 ID 或指向正确的文档吗?
您可以使用从 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;
}