首页 > 解决方案 > 如何在 Microsoft Bot Framework v.3 (Node.js) 中发送欢迎消息并自动加载特定对话框?

问题描述

我正在尝试在我的机器人启动时显示欢迎消息并加载特定对话框。我们在我工作的公司中使用第 3 版(我知道,它很旧且不受支持)。

至于欢迎信息,https://docs.microsoft.com/en-us/azure/bot-service/nodejs/bot-builder-nodejs-handle-conversation-events?view=azure-bot-service-3.0说使用on conversationUpdate,效果很好,但这似乎与https://blog.botframework.com/2018/07/12/how-to-properly-send-a-greeting-message-and-common-issues相矛盾-from-customers/,这表明不应使用conversationUpdate除非使用 DirectLine,而是发送事件。这是对此事的最终决定吗?有没有更好的办法?

我还想在欢迎消息之后自动加载一个对话框。我该怎么做呢?我可以在上面的“on conversationUpdate”事件期间访问会话并直接在那里加载对话框吗?有没有更好的办法?

谢谢你的帮助!

标签: node.jsbotframework

解决方案


这是矛盾的,但conversationUpdate在大多数情况下可能是你最好的选择。但是,由于渠道对此的处理方式不同,因此您应该知道结果可能会有所不同。对于直线,使用发送事件是一个更好的选择。

一个例子,以备不时之需:

bot.on('conversationUpdate', function(message) {
  if (message.membersAdded) {
    message.membersAdded.forEach(function(identity) {
      if (identity.id === message.address.bot.id) {
        var reply = new builder.Message()
          .address(message.address)
          .text("Welcome");
        bot.send(reply);
      }
    });
  }
});

要立即调用特定对话框,请执行以下操作:

bot.on('conversationUpdate', function (message) {
  if (message.membersAdded) {
    message.membersAdded.forEach(function (identity) {
      if (identity.id === message.address.bot.id) {
        bot.beginDialog(message.address, '/main');
      }
    });
  }
});

bot.dialog('/main', [
  function (session, args, next) {
    session.send("Glad you could join.");
    session.beginDialog('/next');
  }
]);

只需将两者结合起来发送欢迎消息并启动对话。

希望有帮助!


推荐阅读