【问题标题】:Microsoft QnA maker - Welcome message loopMicrosoft QnA maker - 欢迎消息循环
【发布时间】:2017-06-15 16:00:13
【问题描述】:

我正在尝试实现类似于在这个主题上所做的事情 Begin Dialog with QnA Maker Bot Framework recognizer (Node JS)

该建议的工作原理是让机器人首先发送欢迎消息,然后等待问题。 然而,机器人现在说'Hj!我有什么可以帮助你的吗?”,等待问题,然后再次回到欢迎状态。

有点像

答:嗨!我怎么帮你? 问:汽车维修号码是多少 A: 拨打 500-XXXX 等。 问:假期我应该联系谁? 答:嗨!有什么可以帮助你的吗?

我玩了 beginDialog,结束对话,替换对话.. 但是没有运气。

这是最新的代码。

bot.dialog('/', [
    function (session ) {
          session.beginDialog('/welcome');
        }, 
    function (session)  {
        session.beginDialog('/qna');
}
]) ;



bot.dialog('/welcome', [
        function (session) {
            // Send a greeting and show help.
            builder.Prompts.text(session, "Hi! How can I help you?");
            //  session.endDialog();
        }
    ]);


bot.dialog('/qna',  basicQnAMakerDialog   ) ;

【问题讨论】:

    标签: javascript node.js azure botframework azure-language-understanding


    【解决方案1】:

    下面的代码示例展示了如何侦听新用户连接到机器人时触发的 conversationUpdate 事件。又名“欢迎信息”:

    // Listen for 'conversationUpdate' event to detect members joining conversation.
    bot.on('conversationUpdate', function (message) {
        if (message.membersAdded) {
            message.membersAdded.forEach(function (identity) {
                if (identity.id == message.address.bot.id) {
                    // Bot is joining conversation
                    // - For WebChat channel you'll get this on page load.
                    var reply = new builder.Message()
                            .address(message.address)
                            .text("Welcome to my page");
                    bot.send(reply);
                } else {
                    // User is joining conversation
                    // - For WebChat channel this will be sent when user sends first message.
                    // - When a user joins a conversation the address.user field is often for
                    //   essentially a system account so to ensure we're targeting the right 
                    //   user we can tweek the address object to reference the joining user.
                    // - If we wanted to send a private message to teh joining user we could
                    //   delete the address.conversation field from the cloned address.
                    var address = Object.create(message.address);
                    address.user = identity;
                    var reply = new builder.Message()
                            .address(address)
                            .text("Hello %s", identity.name);
                    bot.send(reply);
                }
            });
        }
    });
    

    【讨论】:

    • 谢谢,但这并不能解决问题。对话框仍然遵循相同的模式:欢迎消息,回答,然后再次欢迎消息。我希望能够只显示一次欢迎消息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-24
    • 2017-11-01
    • 2021-09-18
    • 2021-10-12
    • 2021-01-25
    • 2021-04-11
    • 1970-01-01
    相关资源
    最近更新 更多