如何使用MS bot框架从Teams私人消息中获取用户上下文 [英] How to get user context from Teams private message using MS bot framework
问题描述
我当前正在实施一个Teams机器人,该机器人必须获取用户名(名字和姓氏)以及通过个人聊天与该机器人进行通信的人员的用户电子邮件地址.
I am currently implementing a Teams bot that has to get the user name (first name and last name) and the user's email address of the person communicating with the bot via a personal chat.
我正在使用机器人框架的 SDK v4 ,并尝试实施此处提到的方法( https://github.com/OfficeDev/BotBuilder-MicrosoftTeams-dotnet ).获取团队上下文时返回的唯一参数是租户ID".频道和团队都为空(我想这是因为我正在私人聊天中?).
I am using SDK v4 of the bot framework and tried to implement the approach mentioned here (https://github.com/OfficeDev/BotBuilder-MicrosoftTeams-dotnet). The only parameter returned when fetching the teams context is the Tenant Id. Both channel and team are null (I presume this is because I am in a private chat?).
既然我现在有了Teams上下文中的租户ID,如何使用它来检索用户的信息?
Since I now have the tenant id from the Teams context, how do I use it to retrieve the user's info?
要检索团队"上下文,请致电以下内容:
To retrieve the Teams context I'm calling the following:
ITeamsContext teamsContext = turnContext.TurnState.Get<ITeamsContext>();
推荐答案
使用ITeamsContext对象检索ID后,您需要使用这些ID来完全填充Teams对象.您可以使用Operations.FetchTeamDetailsAsync方法来执行此操作.
Once you retrieve the IDs using the ITeamsContext object, you need to use those Ids to fully populate the Teams object. You can do so using the Operations.FetchTeamDetailsAsync method.
要获取对话中的成员花名册,请使用GetConversationParametersForCreateOrGetDirectConversation()方法. #epic方法名称.
To get a roster of members in the conversation, you'll use the GetConversationParametersForCreateOrGetDirectConversation() method. #epicmethodname.
using Microsoft.Bot.Builder.Teams;
using Microsoft.Bot.Schema.Teams;
using Microsoft.Bot.Connector.Teams;
...
ConversationList channels = await teamsContext.Operations.FetchChannelListAsync(incomingTeamId);
TeamDetails teamInfo = await teamsContext.Operations.FetchTeamDetailsAsync(incomingTeamId);
var roster = teamsContext.GetConversationParametersForCreateOrGetDirectConversation(turnContext.Activity.From).Members;
List<TeamsChannelAccount> rosterTC = roster.ToList().ConvertAll(member =>
{
return teamsContext.AsTeamsChannelAccount(member);
});
await turnContext.SendActivityAsync($"You have {roster.Count} number of people in this group. You are {from.Name}");
您可以在此处找到一些入门帮助和其他资源: https://developer.microsoft.com/zh-CN/office/blogs/preview-release-of-net-teams-bot-builder-v4-sdk /
You can find some getting started help, and additional resources here: https://developer.microsoft.com/en-us/office/blogs/preview-release-of-net-teams-bot-builder-v4-sdk/
这篇关于如何使用MS bot框架从Teams私人消息中获取用户上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!