我正在使用nodejs v4版本的botbuilder https://learn.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 中,您可以访问 REST API使用getConversationMembers
功能:
/**
*
* @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);
}
请引用documentation和 samples更好地了解如何使用 v4 SDK。
关于node.js - Microsoft bot builder V4 Nodejs 获取用户电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59134234/