Search code examples
dialogbotframeworkresetcortana

I want to restart my watterfall dialog at it's beginning when it ends, using C#


I'm using the Bot Framework .Net SDK4. I start my Dialog at MainDialog. I'm trying to restart my dialog when the watterfall dialog conversation ends. I have multiple watterfall that redirect to other watterfall dialogs, unti they reach the final one. When I'm using stepContext.EndDialogAsync(null, cancellationToken) or stepContext.CancellAllDialogsAsync(cancellationToken), the dialog just returns to the previous parent dialog. I also can't just use BeginDialogAsync(nameof(MainDialog), null, cancellationToke) because of circular dependency issues. Is there anything I can do to restart my dialog at MainDialog, where it reruns tehe dialog again. enter image description here


Solution

  • use

     return await sc.ReplaceDialogAsync(nameof(NoUnderstandDialog), cancellationToken);
    

    To restart the waterfall dialog you are currently in.

    ReplaceDialogAsync :

    Starts a new dialog and replaces on the stack the currently active dialog with the new one. This is particularly useful for creating loops or redirecting to another dialog.

    You can use this for multiple reasons, validation for example if the user inputs a wrong value, you can restart the dialog to prompt again. Be careful though your waterfall dialog should always "ends" meaning it should have a EndDialogAsync so you don't get stuck in an endless loop