如何在Bot Framework中获取用户详细信息 [英] How to get user details in Bot Framework
问题描述
我正在建立一个Teams Bot,该机器人需要向用户发送自适应卡.
I am building a Teams Bot which needs to send out Adaptive Cards to users.
安装机器人后,我正在向用户发送欢迎消息.从欢迎消息中,我可以使用activity.from.id获取用户的团队ID.
When the bot is installed, i am sending a Welcome message to the user. From the welcome message, i am able to get the user's Teams ID using activity.from.id.
来自ID :: 29:1O_abckkskldjflkjfslxxxxxxxx
使用此ID,我尝试使用获取用户详细信息 const member = TeamsInfo.getMember(context,context.activity.from.id);
With this id, i tried to get the User Details using
const member=TeamsInfo.getMember(context, context.activity.from.id);
但是,我仍然无法获取用户详细信息.
However I am still unable to get the user details.
如何获取用户的电子邮件ID,以便将来我可以向用户发送通知?
How to get the email id of the user so that in future i can send notifications to the user ?
推荐答案
根据文档,您将传递"id"仅适用于dotnet库的getMember.对于Node,它似乎需要电子邮件/UPN-请参阅 getPagedMembers -如果只有一个用户(即1-1聊天),则实际上与getMember相同.
According to the docs, you pass the "id" to getMember only for the dotnet libraries. For Node, it looks like it wants the email/UPN - see here, whereas you're sending activity.from.id. Perhaps try call getPagedMembers instead - if there's only one user (i.e. it's a 1-1 chat), it's effectively the same as getMember.
工作片段::
this.onMembersAdded(async (context, next) => {
const membersAdded = context.activity.membersAdded;
for (let cnt = 0; cnt < membersAdded.length; ++cnt) {
if (membersAdded[cnt].id !== context.activity.recipient.id) {
var continuationToken;
var members = [];
do {
var pagedMembers = await TeamsInfo.getPagedMembers(context, 100, continuationToken);
continuationToken = pagedMembers.continuationToken;
members.push(...pagedMembers.members);
} while (continuationToken !== undefined);
members.forEach(member => {
const userEmail=member.userPrincipalName;
});
const card = CardFactory.adaptiveCard(welcomeCard);
const message = {
attachments: [card],
summary: 'Welcome'
};
await context.sendActivity(message);
}
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
这篇关于如何在Bot Framework中获取用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!