【问题标题】:Switches between Dialog in Microsoft Bot Framework (Node.js)在 Microsoft Bot Framework (Node.js) 中的对话框之间切换
【发布时间】:2017-11-28 17:28:42
【问题描述】:

我在 Microsoft Bot Framework 上编写了一个机器人。我使用了 LUIS 语言模型。 下面是我的一段代码:

bot.use(builder.Middleware.dialogVersion({ version: 1.0, resetCommand: /^reset/i }));
bot.dialog('/', intents);

intents.matches('GoogleHome', [

    function (session, args) {
    if(builder.EntityRecognizer.findEntity(args.entities, 'cookingtips'))
    {
            quickReply(session, args)
    }
    if(builder.EntityRecognizer.findEntity(args.entities, 'wakingtips'))
    {
            //My rest of the code
    }

}])

这是我的快速回复的代码

function quickreply(session, args){

    var msg = new builder.Message(session)
                .text("Let me know the date and time you are comfortable with..")
                .suggestedActions(
                    builder.SuggestedActions.create(
                        session,[
                            builder.CardAction.imBack(session, "CookingTips", "CookingTips"),
                            builder.CardAction.imBack(session, "WalkingTips", "WalkingTips")

                        ]
                    )
                );
            builder.Prompts.choice(session, msg, ["CookingTips", "WalkingTips"]), function(session,results) {
             console.log(results);
            session.send('So I understand you want a cooking tip ' +  results + ' right now');
            session.endDialog();
        }}

我能够得到快速回复,点击后什么也没有发生。我在控制台中看到以下内容:

.BotBuilder:prompt-choice - Prompt.returning([object Object])
.BotBuilder:prompt-choice - Session.endDialogWithResult()
/ - Session.endDialogWithResult()

相反,我希望将此消息发送到我的 LUIS,或者至少显示回调函数中所写的确认消息。我该怎么做?

【问题讨论】:

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


    【解决方案1】:

    由于您的quickReply() 函数不会创建新对话框,因此endDialog() 将终止当前对话框,并且由于您没有父对话框,因此无法返回到恢复对话框。

    您可以利用next 中间来传递值,将您的代码修改为:

    intents.matches('GoogleHome', [
    
        function (session, args, next) {
        if(builder.EntityRecognizer.findEntity(args.entities, 'cookingtips'))
        {
                quickReply(session, args, next)
        }
        if(builder.EntityRecognizer.findEntity(args.entities, 'wakingtips'))
        {
                //My rest of the code
        }
    
    },(session,result)=>{
    //get the user choice here
        console.log(result);
        session.send(JSON.stringify(result));
    }])
    

    快速回复

    function quickRelpy(session, args, next) {
        var msg = new builder.Message(session)
            .text("Let me know the date and time you are comfortable with..")
            .suggestedActions(
                builder.SuggestedActions.create(
                    session, [
                        builder.CardAction.imBack(session, "CookingTips", "CookingTips"),
                        builder.CardAction.imBack(session, "WalkingTips", "WalkingTips")
    
                    ]
                )
            );
        builder.Prompts.choice(session, msg, ["CookingTips", "WalkingTips"]);
    }
    

    【讨论】:

    • 嗨,加里。我试过了,但它不能正常工作。您可以填写获取用户选择的代码吗?我觉得我做得很好。
    • 添加一些代码sn-p,使其更清晰。基本上,您的机器人将在下一个瀑布中收到用户的消息。
    猜你喜欢
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 2020-02-25
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多