How to get user context from Teams private message using MS bot framework

不想你离开。 提交于 2019-12-06 15:36:42

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.

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}");

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!