【问题标题】:Microsoft bot builder V4 nodejs fetching user emailMicrosoft bot builder V4 nodejs 获取用户电子邮件
【发布时间】:2019-12-03 07:43:47
【问题描述】:

我正在使用 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
             }

【问题讨论】:

  • 你用的是什么渠道?
  • 微软团队

标签: node.js botframework


【解决方案1】:

在 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);
}

请参阅documentationsamples 以更好地了解如何使用 v4 SDK。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 2019-07-27
    • 1970-01-01
    • 2015-11-10
    相关资源
    最近更新 更多