Bot framework v4.0 how to execute the previous waterfall step in a dialog

后端 未结 3 1284
太阳男子
太阳男子 2020-12-11 02:31

I\'m trying to create a dialog in which I define multiple waterfall steps. In the context of this dialog, I need sometimes to go back to the previous waterfall step accordin

3条回答
  •  不知归路
    2020-12-11 03:10

    You can use the option parameter in the method "ReplaceDialogAsync" and skip steps with the method "NextAsync".

    For example in my waterfall steps (defined in the constructor):

            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                IntroStepAsync,
                ActStepAsync,
                FinalStepAsync
            }));
    
            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
    

    If you want pass to second step (in my case ActStepAsync) from the final step (FinalStepAsync) , when I going to replace the dialog I use the created a label in the Dialog:

    private const string FLAG = "MY_FLAG";
    

    When I invoke the method from final step I do this :

    return await stepContext.ReplaceDialogAsync(InitialDialogId, FLAG, cancellationToken);
    

    So I only need check the option in the first step if the context has the flag :

        // Use the text provided in FinalStepAsync or the default if it is the first time.
            var messageText = stepContext.Options?.ToString() ?? "welcome-message";
            if (messageText.Equals(FLAG_REPROMPT))
            {
                return await stepContext.NextAsync(null,cancellationToken);
            }
    

    Later this you are in the second step

提交回复
热议问题