gpt4 book ai didi

node.js - 在提示中间中断的对话框仅从提示步骤开始处恢复

转载 作者:太空宇宙 更新时间:2023-11-04 01:56:09 25 4
gpt4 key购买 nike

我正在尝试设计一个订餐机器人。有一个“orderDinner”对话框,它只有两个功能——>提示文本和处理响应。在“orderDinner”对话框的上下文中,beginDialogAction 是为了触发“alcohol”而完成的。它调用一个新对话框“checkAge”。我想要的是在 checkAge 完成并验证年龄后,“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)
}
]);

有什么办法可以在不破坏流程的情况下实现这一目标吗?现在,消息:永远不会打印“酒精添加到购物车”

最佳答案

您在 orderDinner 对话框中的函数中传递了错误的参数,该函数应该是实现 IDialogWaterfallStep 接口(interface)的对话框或对话框数组,并且 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
});
}

关于node.js - 在提示中间中断的对话框仅从提示步骤开始处恢复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47917778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com