有没有办法在中断后将自定义数据返回到提示符?

问题描述 投票:1回答:1

我希望我能清楚这个问题。我的问题是我想使用简单的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 luis
1个回答
0
投票

我将假设你正在处理的提示类型是Prompt.confirm,它基于你试图传递的NegativeAnswerTriggeredDialog对话框。

问题是triggerAction根据the BotBuilder Handle User Actions documentation它默认清除Dialog堆栈。来自文档:

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

您可能希望使用customActions,它直接绑定到bot而不是Dialog对象。

考虑我的代码示例,其中我有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是Yes / No提示,因此将“Yes”映射到true并将“No”映射到false。它不会将您尝试传递的对象传递给代码示例。在我的测试运行中,基于我设置的LUIS Intents,“是的”,“当然”和“是”都映射到“是”。映射到“否”的“否定”,“不”和“我不这么认为”(以及其他变体)您的设置可能在LUIS意图方面有所不同。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.