[英]ChatBot back to previous dialog
I've created a chatbot using Node.js and the flow of dialogs works fine til the endDialog.我使用 Node.js 创建了一个聊天机器人,对话框流程在结束对话框之前运行良好。 Im having issues implementing a back option so it can jump back only to previous dialog.
我在实现后退选项时遇到问题,因此它只能跳回到上一个对话框。 Can anyone please guide me how to solve that?
谁能指导我如何解决这个问题?
.reloadAction(
"restartBenefits", "Ok. Let's start over.",
{
matches: /^start over$|^restart$/i
}
)
.cancelAction(
"cancelRequest", "Thank you for reaching out, Good bye!",
{
matches: /^nevermind$|^cancel$|^cancel.*request/i,
confirmPrompt: "This will cancel your request. Are you sure?"
}
);
Use a customAction
使用
customAction
In this case you can listen for whatever you want to be a keyword for "back" and then simply route the user back to that dialog using replaceDialog
在这种情况下,您可以侦听要用作“ back”关键字的任何内容,然后使用
replaceDialog
将该用户简单地路由回该对话框。
bot.customAction({
matches: /back|last/gi, //whatever prompts you want to match.
onSelectAction: (session, args, next) => {
session.replaceDialog(PreviousDialog); //variable with the last dialog in it, set that somewhere, such as the end of your previous dialog
}
})
I think that at the final step of the dialog waterfall you need to add the last lines in this sample step:我认为在对话瀑布的最后一步,您需要在此示例步骤中添加最后几行:
/** * This is the final step in the main waterfall dialog. * It wraps up the sample "book a flight" interaction with a simple confirmation. */ async finalStep(stepContext) { // If the child dialog ("bookingDialog") was cancelled or the user failed to confirm, the Result here will be null. if (stepContext.result) { const result = stepContext.result; // Now we have all the booking details. // This is where calls to the booking AOU service or database would go. // If the call to the booking service was successful tell the user. const timeProperty = new TimexProperty(result.travelDate); const travelDateMsg = timeProperty.toNaturalLanguage(new Date(Date.now())); await stepContext.context.sendActivity(ActivityFactory.fromObject(this.lgTemplates.evaluate('BookingConfirmation', { Destination: result.destination, Origin: result.origin, DateMessage: travelDateMsg }))); } // =====> HERE: Restart the main dialog with a different message the second time around return await stepContext.replaceDialog(this.initialDialogId, { restartMsg: 'What else can I do for you?' }); }
Just change the this.initialDialogId
accordingly.只需相应地更改
this.initialDialogId
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.