![](/img/trans.png)
[英]use await inside callback (Microsoft Bot Framework v4 nodejs)
[英]Microsoft bot builder V4 nodejs fetching user email
我正在使用 nodejs v4 版本的 botbuilder https://docs.microsoft.com/en-us/javascript/api/botbuilder/?view=botbuilder-ts-latest
我当前的代码是从 echo bot 中选取的,如下所示
const { ActivityHandler } = require('botbuilder');
class ScanBuddyMsBot extends ActivityHandler {
constructor() {
super();
this.onMessage(async (context:any, next:any) => {
await context.sendActivity(`You said '${ context.activity.text }'`);
// By calling next() you ensure that the next BotHandler is run.
await next();
});
}
}
module.exports.ScanBuddyMsBot = ScanBuddyMsBot;
我正在寻找一种方法来获取向我的机器人发送消息的用户电子邮件。 我可以在上下文活动、对话 id 和服务 url 中看到,但看不到电子邮件 id。
在另一个变体中,我使用下面的方式来获取电子邮件 ID,但不确定如何使下面的代码适用于上面
var bot = new builder.UniversalBot(connector, async function(session) {
var teamId = session.message.address.conversation.id;
connector.fetchMembers(
session.message.address.serviceUrl,
teamId,
async (err, result) => {
if (err) {
session.send('We faced an error trying to process this information', err);
return
}
else {
const email = result[0].email
}
在 Bot Builder v4 中,您可以使用getConversationMembers
函数访问该REST API :
/**
*
* @param {TurnContext} turnContext
*/
async testTeams(turnContext) {
const activity = turnContext.activity;
const connector = turnContext.adapter.createConnectorClient(activity.serviceUrl);
const response = await connector.conversations.getConversationMembers(activity.conversation.id);
const email = response[0].email;
await turnContext.sendActivity(email);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.