1

The scenario is as follows:

In case the input provided by user seems incorrect in a waterfall step (e.g. incorrect name, incorrect date) User would like to enter the last input again by saying “ (reenter)” or (enter again) .

It’s like if there are three steps in waterfall dialog: Step1->Step2->Step3

After providing input for Step2, if user sees the input to be incorrect he would like to interrupt the flow by saying any of the words mentioned above to enter input for previous step.

I could not find a way to go back to previous waterfall step.

There are few solution available to go back to previous step but I was unable to replicate the same in python.

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

Link2:- https://pauliom.com/2018/08/08/manipulating-waterfall-steps-botframework-v4/

I tried handling the scenario using interrupt but the issue persists as the next Turn continues from where the conversation left off.

Abhijeet
  • 176
  • 2
  • 12

2 Answers2

2

What you can use is Validators, check this article for more information or find below code snippets [c#] as a summary.
I have also added a Python snippet in the end

When a user replies to your prompt the validation will be triggered. If the validation returns false, a retry prompt will be sent to the user

There is no need to go back to the previous step if you implement validators

            AddDialog(new TextPrompt("TextPromptId", UserNameValidation));
            AddDialog(new NumberPrompt<int>("NumberPromptId", MobileNumberValidation));
            AddDialog(new ChoicePrompt("ChoicePromptId", ChoiceValidataion));

Username Validator:


    private Task<bool> UserNameValidation(PromptValidatorContext<string> promptContext, CancellationToken cancellationToken)  
           {  
               return Task.FromResult(true);  
           } 

Choice Validator:



    private Task<bool> ChoiceValidataion(PromptValidatorContext<FoundChoice> promptContext, CancellationToken cancellationToken)  
            {  
                return Task.FromResult(true);  
            }  

Mobile Phone Validator:




    private async Task<bool> MobileNumberValidation(PromptValidatorContext<int> promptcontext, CancellationToken cancellationtoken)  
            {  
                if (!promptcontext.Recognized.Succeeded)  
                {  
                    await promptcontext.Context.SendActivityAsync("Hello, Please enter the valid mobile no",  
                        cancellationToken: cancellationtoken);  

                    return false;  
                }  

                int count = Convert.ToString(promptcontext.Recognized.Value).Length;  
                if (count != 10)  
                {  
                    await promptcontext.Context.SendActivityAsync("Hello , you are missing some number !!!",  
                        cancellationToken: cancellationtoken);  
                    return false;  
                }  

                return true;  
            }   

I am not a Python developer but you find a python sample in Here in the Python tab and the below snippet:

async def age_prompt_validator(prompt_context: PromptValidatorContext) -> bool:
    # This condition is our validation rule. You can also change the value at this point.
    return (
        prompt_context.recognized.succeeded
        and 0 < prompt_context.recognized.value < 150
    )

Hope that helps

Marc Asmar
  • 1,527
  • 1
  • 10
  • 22
  • The solution you mentioned is to validate a user input to prompts. But the scenario here is different,lets say i have validated the prompt input and moved on to next step and user finds out the input entered to be incorrect. So, the user would like to provide input for the previous step again. – Abhijeet May 29 '20 at 12:00
  • 2
    @Abhijeet In C# I am achieving this by editing the Active Dialog's state's step index like this: // go back 1 previous step sc.ActiveDialog.State["stepIndex"] = (int)sc.ActiveDialog.State["stepIndex"] - 2; return await sc.NextAsync(); – Marc Asmar May 29 '20 at 12:22
  • Maybe i am unable to explain the scenario. In my case lets say i have step1->step2. I have validated the user input for step1 and moved on to step2 and then the user wants to change input for the previous step i.e step1. How should i do that? Any idea? – Abhijeet May 29 '20 at 12:34
  • 1
    The above solution works in python as: step_context.active_dialog.state['stepIndex']=step_context.active_dialog.state['stepIndex] - 2 – Abhijeet Jun 02 '20 at 05:38
0

You could build something using a choice prompt at the end of each step using component dialogs. So user enters a name, Bot responds with ‘Is this what you entered?’ User confirms yes, next step fires, user says no, that dialog is re-run.

I had a similar question earlier this month myself Repeating a dialog step based on validation

Steve Johnson
  • 405
  • 3
  • 8