2

I've created a chatbot using Node.js and the flow of dialogs works fine til the endDialog. 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?"
    }
);
migena22
  • 21
  • 2
  • 2
    Please add the relevant code, any error messages, and other necessary information. – Bhesh Gurung Aug 30 '18 at 20:12
  • // in each Dialog I have a reload (startover) and cancel action, i need a back action as well, but was not able to find something about it: .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?" } ); – migena22 Aug 31 '18 at 12:35
  • Hi @Migena22! Can you edit your post to place this information in it? You can format your post so that code shows clearly. It is very difficult to read in this comment. – JJ_Wailes Aug 31 '18 at 14:35
  • 1
    @JJ_Wailes I edited the main post. thnx – migena22 Aug 31 '18 at 15:19
  • 2
    Hi, by 'jump back only to previous dialog', do you mean jump to a previous waterfall step, or jump back to a parent dialog? – Corina Sep 24 '18 at 05:40
  • I think he meant parent - right ? – Gel Feb 14 '22 at 14:36

2 Answers2

0

Use a 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

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
    }
})
Mark B
  • 581
  • 2
  • 14
  • but, if the dialogue ends, it should automatically go back to parent. Why would we ask the user to type in `back` or any synonymous word.. – Gel Feb 14 '22 at 14:37
  • @Gel It's certainly not the only way, but in this case I'm just answering the question as written. – Mark B Mar 31 '22 at 18:17
0

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.

Gel
  • 2,866
  • 2
  • 18
  • 25