在提示中间中断的对话框仅从提示步骤的开头重新开始

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

我正在尝试设计一个晚餐订购机器人。有一个'orderDinner'对话框,它只有两个函数 - >提示文本并处理响应。在'orderDinner'对话框的上下文中,beginDialogAction用于触发'alcohol'。它调用一个新的对话框'checkAge'。我想要的是在checkAge完成并且age验证后,'orderDinner'对话框应该从第2步恢复,但它总是从第1步开始。下面是代码:

bot.dialog('orderDinner', [
function (session, args){
    let promptmessage;
    if (args && args.resumed == true) {
        promptmessage = 'What else would you like to add?';
    } else {
        promptmessage = 'What would you like to order today?';
    }
    promptmessage += '(_type done when no more items to add_)';
    builder.Prompts.text(session, promptmessage);
},
function (session, results, args) {
    session.send(`${results.response} added to dinner cart!`);
    session.replaceDialog('orderDinner', {
        resumed : true
    });
}
]).beginDialogAction('checkAge', 'checkAge', {
    matches: /^alcohol$/i
}).beginDialogAction('doneOrderDinner', 'doneOrderDinner', {
    matches: /^done$/i
})

bot.dialog('doneOrderDinner',[
    (session) => {
        session.send("Food will be on your way");
        session.replaceDialog('mainBotMenu');
    }
])

bot.dialog('checkAge', [
    (session, result) => {
        builder.Prompts.number(session, 'Please enter your age');
    },
    (session, result) => {
        let canGetAlcohol = false;
        if(result.response > 18) {
            session.send('You can get alcohol');
            canGetAlcohol = true;
        } else {
            session.send('Too young for alcohol');
        }
        const dialogResult = { resumed : true, canGetAlcohol : canGetAlcohol }
        session.endDialogWithResult(dialogResult)
    }
]);

有没有办法在不破坏流量的情况下实现这一目标?现在,从未打印过“添加到购物车的酒精”的消息

node.js botframework
1个回答
0
投票

你在orderDinner对话框中的函数中传递了错误的参数,该函数应该是一个实现IDialogWaterfallStep接口的对话框或对话框数组,而IDialogWaterfallStep是这样的:

export interface IDialogWaterfallStep {
    /**
     * @param session Session object for the current conversation.
     * @param result
     * * __result:__ _{any}_ - For the first step of the waterfall this will be `null` or the value of any arguments passed to the handler.
     * * __result:__ _{IDialogResult}_ - For subsequent waterfall steps this will be the result of the prompt or dialog called in the previous step.
     * @param skip Function used to manually skip to the next step of the waterfall.
     * @param skip.results (Optional) results to pass to the next waterfall step. This lets you more accurately mimic the results returned from a prompt or dialog.
     */
    (session: Session, result?: any | IDialogResult<any>, skip?: (results?: IDialogResult<any>) => void): any;
}

所以在你的代码中,参数resumed应该在变量results中。现在您可以修改代码,例如:

function (session, args){
    let promptmessage;
    if (args && args.resumed) {
        promptmessage = 'What else would you like to add?';
    } else {
        promptmessage = 'What would you like to order today?';
    }
    promptmessage += '(_type done when no more items to add_)';
    builder.Prompts.text(session, promptmessage);
},
function (session, results) {
    session.send(`${results.response} added to dinner cart!`);
    session.replaceDialog('orderDinner', {
        resumed : true
    });
} 
© www.soinside.com 2019 - 2024. All rights reserved.