0
votes

I am creating a WebChatBot using C# in SDK V4 with multiple dialog classes having waterfall steps. In one of the dialogClass which I redirected int after successful authentication at

STEP1: I am giving user set of ChoicePrompt inside PromptOptions with PromptText, Choices, and RetryPrompt. What I want to do or achieve is if the user enters or types anything other than the Choices it should take the text and reply back the appropriate message. I am not talking about the retry prompt text but something as tried to explain in below example:

1. STEP #1: User is given PomptOptions of type Choice prompt such as return

await stepContext.PromptAsync(
                    "SchedulechoicePrompt",
                    new PromptOptions
                    {
                        Prompt = stepContext.Context.Activity.CreateReply("Please choose any of the following options: "),
                        Choices = new[] { new Choice { Value = "one" }, new Choice { Value = "Two" }, new Choice { Value = "Three" } }.ToList(),
                        RetryPrompt = stepContext.Context.Activity.CreateReply("Sorry, I did not understand that. Please choose/click on any one of the options displayed in below list to proceed"), 
                    });

Now if user enters something which is not present in above lets say four

Currently it displays the text of retry prompt

What i am trying to achieve is take this 4 and display custom message this is not a valid option IF i enter the login ID which I used for authentication before I got redirected to this dialog i should say a custom message saying you have already logged in here are your options where the 1,2,3 options displayed again If i enter another login ID i should display a custom message this is not the user ID you used to login should be displayed and again prompt option should be displayed

Now if i enter anything synonymous to the options displayed like:1 then it should go to next STEP i.e

STEP#2 and execute the related functionality.

IF anything else then retryprompt text should be displayed and again prompt option should be displayed

STEP #2: Desired operation will be executed if the selected choice matches

If you see it would seem like to have text prompt and choice prompt(displayed with prompt options) both at a time or both should work in parallel?

Now,can any one tell in detailed step by step guide or manner how to achieve this if it can be done in V4 using waterfall in C#?

Or It cannot be achieved this is incorrect expectation?

Language: C# SDK: V4 All the Nuget packages and bot emulator are latest

Please let me know step by step or as detailed as possible as i am new to coding and also in Bot, i need it detailed for understanding.

Did not get anything how to achieve it in V4 C#?

n/a as i do not now how to do it.

Expected Result: ChoiceOptions displayed as part of PromptOptions should work along with text input provided and based on text input provided dsiplay custom message and display the options again if it is incorrect input or else if it is synonymous or the given option is selected in STEP#1 then in STEP#2 the related process will be executed.

Actual Result: n/a

1

1 Answers

1
votes

I have tried out something like that. You could use a parent dialog and let your current dialog inherit it. Check for turn level interruptions, process the user input and then continue from where the dialog left off.

Inside the parent dialog, implement InterruptAsync method and process the user input.

 private async Task<DialogTurnResult> InterruptAsync(DialogContext innerDc,CancellationToken cancellationToken)
 {
 if (innerDc.Context.Activity.Type == ActivityTypes.Message)
 {
    var text = innerDc.Context.Activity.Text.ToLowerInvariant();

    switch (text)
    {
        case "help":
        case "?":
            await innerDc.Context.SendActivityAsync($"Show Help...", cancellationToken: cancellationToken);
            return new DialogTurnResult(DialogTurnStatus.Waiting);

        case "cancel":
        case "quit":
            await innerDc.Context.SendActivityAsync($"Cancelling", cancellationToken: cancellationToken);
            return await innerDc.CancelAllDialogsAsync();
    }
}

return null;

}

As case statements, you could write different scenarios of user input.

I found this documentation useful: https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-handle-user-interrupt?view=azure-bot-service-4.0&tabs=csharp