简体   繁体   English

ChatBot 返回上一个对话框

[英]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.

相关问题 如何将 go 返回到 AWS Amplify CLI 身份验证配置中的上一项? - How to go back to previous item in AWS Amplify CLI auth configuration? React js go 登录后返回上一页 - React js go back to previous page after sign in Twilio 聊天机器人与网站集成 - Twilio chatbot integration with websites 每当我单击一个活动时,应用程序都会被压碎或将用户送回之前的活动。解决方案是什么? - Whenever I click an activity ,app is get crushed or sent back user to previous activity.What is The solution of this? 我的应用程序返回到上一页而没有将数据更新到数据库。 (使用 Android studio + Firebase) - My app is gets back to previous page without updating data to database. (Using Android studio + Firebase) 如何在 Dialogflow 聊天机器人中实现登录 - How to implement Login in Dialogflow chatbot 使用 kommunicate 在 dialogflow 聊天机器人中链接 - Link in dialogflow chatbot using kommunicate 使用 Dialogflow 和 BigQuery ML 实现服务台聊天机器人的问题 - Issue with Implementing a Helpdesk Chatbot with Dialogflow & BigQuery ML 如何在 Dialogflow 聊天机器人中获取用户的当前位置? - How to get the current location of a user in Dialogflow chatbot? 如何获得聊天机器人的聊天对话(在 aws lex 中) - How to get chat-conversation of chatbot(in aws lex)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM