2

The PromptDialog.Choice in the Bot Framework display the choice list which is working well. However, I would like to have an option to cancel/escape/exit the dialog with giving cancel/escape/exit optioin in the list. Is there anything in PromptDialog.Choice which can be overridden since i have not found any cancel option.

here is my code in c#..

PromptDialog.Choice( context: context, resume: ChoiceSelectAsync, options: getSoftwareList(softwareItem), prompt: "We have the following software items matching " + softwareItem + ". (1), (2), (3). Which one do you want?:", retry: "I didn't understand. Please try again.", promptStyle: PromptStyle.PerLine); 

Example:

Bot: We have the following software items matching Photoshop. (1), (2), (3). Which one do you want

  • Version 1
  • Version 2
  • Version 3

What I want if user enter none of above or a command or number, cancel, exit, that bypasses the options above, without triggering the retry error message.

How do we do that?

3 Answers 3

3

There are two ways of achieving this:

  1. Add cancel as an option as suggested. While this would definitely work, long term you will find repeating yourself a lot, plus that you will see the cancel option in the list of choices, what may not be desired.
  2. A better approach would be to extend the current PromptChoice to add your exit/cancelation logic. The good news is that there is something already implemented that you could use as is or as the base to achieve your needs. Take a look to the CancelablePromptChoice included in the BotBuilder-Samples repository. Here is how to use it.
Sign up to request clarification or add additional context in comments.

3 Comments

I have gone through the CancleablePromptChoice in botbuilder but i think this does not work with number input, when it shows the list i choose 1 then , again n again show the list. I tried override ScoreMatch method, but it does not return the first item from the list. Is something missing?
I don't think the current Prompt Choice works in that way either. If you want to allow users to select by number, then you might have to update the TryParse/ScoreMatch methods to do your custom logic OR, include the number in the option. I don't think the CancelablePromptChoice is using the ScoreMatch. It was created way before that method was added. You can override that method and call it from the TryParse.
yes you are right current Prompt Choice does not work in that way. I have override the ScoreMatch in CancleablePromptChoice as below
2

Just add the option "cancel" on the list and use a switch-case on the method that gets the user input, then call your main manu, or whatever you want to do on cancel

Comments

0

Current Prompt Choice does not work in that way to allows user select by number. I have override the ScoreMatch function in CancleablePromptChoice as below

public override Tuple<bool, int> ScoreMatch(T option, string input) { var trimmed = input.Trim(); var text = option.ToString(); // custom logic to allow users to select by number int isInt; if(int.TryParse(input,out isInt) && isInt <= promptOptions.Options.Count()) { text = promptOptions.Options.ElementAt(isInt - 1).ToString(); trimmed = option.ToString().Equals(text) ? text :trimmed; } bool occurs = text.IndexOf(trimmed, StringComparison.CurrentCultureIgnoreCase) >= 0; bool equals = text == trimmed; return occurs ? Tuple.Create(equals, trimmed.Length) : null; } 

@Ezequiel Once again thank you!.

1 Comment

Is there any Implementation done for PromtDialog.String or PromtDialog.Int ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.