是否可以使用SDK4从带有Bot的MS Teams获得用户电子邮件? [英] Is it possible to get user email from MS Teams with a Bot using SDK4?
问题描述
我正在使用C#和Bot Framework SDK4,需要通过与我的机器人进行1:1聊天来获取用户电子邮件.是否有可能?我似乎只能得到ID和全名.
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.
我已经尝试过此处列出的内容 https: //docs.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-context 但是teamContext只是返回null.
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?
推荐答案
可以!每个文档,您的操作与获取团队花名册的方法相同,只是使用对话ID.例如:
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 );
注意:我尝试使用 Microsoft.Bot.Connector.Teams
包来执行此操作,但是无法正常工作.必须使用上面的connector
方法.
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.
这篇关于是否可以使用SDK4从带有Bot的MS Teams获得用户电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!