【问题标题】:Is there a way to return custom data to a prompt after interrupting it?有没有办法在中断后将自定义数据返回到提示?
【发布时间】:2018-10-04 06:48:51
【问题描述】:

我希望我能清楚这个问题。 我的问题是我想使用简单的 Luis 触发对话框来将意图/实体发回给定的当前对话框。

即我想将触发对话框与我的业务对话框解耦,定义它们唯一功能是触发并返回相关数据的对话框,例如:

bot.dialog('NegativeAnswerTriggeredDialog', [
    (session, args, next) => {
        var response = { type: 'bool', value: false, index: 1, entity: 'No', score: 1};
        session.endDialogWithResult({ response:response });
    }
]).triggerAction({
    matches: 'NegativeAnswer',
    onSelectAction: (session, args, next) => {
        session.beginDialog(args.action, args);
    }
});

所以,请注意,我只是准备了一些对象,然后我 endDialogWithResult 将此对象交给上一个对话框。

问题是提示不识别这个对象,或者这个对象的格式,我不确定。有没有办法以一种被接受为提示的有效输入的方式返回它?

顺便说一句,我想在这里实现的目标是让用户用自然语言回答提示。

【问题讨论】:

    标签: node.js nlp botframework bots azure-language-understanding


    【解决方案1】:

    根据您尝试传递的 NegativeAnswerTriggeredDialog 对话框,我将假设您正在处理的提示类型是 Prompt.confirm

    问题是triggerActionthe BotBuilder Handle User Actions documentation 一样,默认情况下它会清除对话框堆栈。来自文档:

    将 triggerAction 绑定到对话框会将其注册到机器人。一旦触发,triggerAction 将清除对话框堆栈并将触发的对话框推入堆栈。此操作最适合用于在对话主题之间切换或允许用户请求任意独立任务。如果要覆盖此操作清除对话框堆栈的行为,请将 onSelectAction 选项添加到 triggerAction。

    您可能想改用customActions,它直接绑定到机器人而不是对话框对象。

    考虑一下我的代码示例,其中有Prompt.confirmPrompt.choice 的对话框:

    bot.dialog('GreetingDialog', [
        (session) => {
            session.send('You reached the Greeting intent. You said \'%s\'.', session.message.text);
            builder.Prompts.confirm(session, "Would you like to learn more?");
        }, (session, results) => {
            console.log(results.response);
            if (results.response) {
                session.endDialog("You're doing your part!");
            } else if (!results.response) {
                session.endDialog("Awwww....  no fun.");
            } else {
                session.endDialog("Something else is going on here.");
            }
        }
    ]).triggerAction({
        matches: 'Greeting'
    });
    
    bot.dialog('HelpDialog',[
        (session) => {
            session.send('You reached the Help intent. You said \'%s\'.', session.message.text);
            builder.Prompts.choice(session, "Pick something colorful", ["Red", "Yellow", "Blue"]);
        }, (session, results) => {
            switch(results.response.entity) {
                case "Red":
                    session.endDialog("Red it is.");
                    break;
                case "Yellow": 
                    session.endDialog("Yellow it is.");
                    break;
                case "Blue":
                    session.endDialog("Blue it is.")
                    break;
                default:
                    session.endDialog("I have no idea what that is.");
            }
        }
    ]).triggerAction({
        matches: 'Help'
    });
    
    bot.customAction({
        matches: 'NegativeAnswer',
        onSelectAction: (session, args, next) => {
            session.endDialogWithResult({response: false});
        }
    });
    
    bot.customAction({
        matches: "PositiveAnswer",
        onSelectAction: (session, args, next) => {
            session.endDialogWithResult({response: true});
        }
    });
    
    bot.customAction({
        matches: "Red",
        onSelectAction: (session, args, next) => {
            session.endDialogWithResult({response: { index: 0, entity: 'Red', score: 1 }});
        }
    });
    
    bot.customAction({
        matches: "Yellow",
        onSelectAction: (session, args, next) => {
            session.endDialogWithResult({response: { index: 1, entity: 'Yellow', score: 1 }});
        }
    });
    
    bot.customAction({
        matches: "Blue",
        onSelectAction: (session, args, next) => {
            session.endDialogWithResult({response: { index: 2, entity: 'Blue', score: 1 }});
        }
    });
    

    Prompt.confirm 是一个是/否提示,因此将“是”映射到true,将“否”映射到false。它不接受您试图在代码示例中传递的对象。在我的测试运行中,根据我设置的 LUIS 意图,“是”、“当然”和“是”都映射为“是”。 “否定”、“不”和“我不这么认为”(以及其他变体)映射到“否”。您的设置可能在 LUIS 意图方面有所不同。

    另一方面,Prompt.choice 期望响应对象包含在“红色”、“蓝色”和“黄色”示例 customActions 中。在这种情况下,我为适当的意图设置了“深红色”、“栗色”、“琥珀色”、“蔚蓝”等可能的话语。

    只要您对每个意图都有预期的可能答案,它就应该映射到正确的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      • 2016-12-26
      • 2022-01-18
      • 1970-01-01
      • 2010-09-30
      相关资源
      最近更新 更多