Is it possible to get user email from MS Teams with a Bot using SDK4?

痴心易碎 提交于 2020-01-30 12:22:05

问题


I'm using C# and Bot Framework SDK4 and need to get the user email from a 1:1 chat with my bot. Is it possible? All I can seem to get is ID and full name.

I have tried the things listed here https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-context but the teamsContext is just returning null.

ITeamsContext teamsContext = turnContext.TurnState.Get<ITeamsContext>();

string incomingTeamId = teamsContext.Team.Id;
string incomingChannelid = teamsContext.Channel.Id;
string incomingTenantId = teamsContext.Tenant.Id;

So is it even possible to get the user email from the current user chatting with the bot?


回答1:


You can! Per the docs, you just do the same as if you were getting the team roster, but use the conversation id, instead. For example:

var credentials = new MicrosoftAppCredentials("<yourAppId>", "<yourAppPassword>");
var connector = new ConnectorClient(new Uri(turnContext.Activity.ServiceUrl), credentials);
var conversationId = turnContext.Activity.Conversation.Id;
var userInfo = await connector.Conversations.GetConversationMembersAsync(conversationId );

Note: I tried using the Microsoft.Bot.Connector.Teams package to do this, but couldn't get it to work. Had to use the connector method above.



来源:https://stackoverflow.com/questions/56918152/is-it-possible-to-get-user-email-from-ms-teams-with-a-bot-using-sdk4

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