繁体   English   中英

在Microsoft Bot Framework(Node.js)中的对话框之间切换

[英]Switches between Dialog in Microsoft Bot Framework (Node.js)

我在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
    }

}])

这是我的quickReply的代码

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或至少显示在回调函数中编写的确认消息。 我该怎么做?

由于您的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"]);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM