Search code examples
botframework

Is there a way to use ChoicePrompt without validating choices?


I would like to present the user with a series of choices, but also allow them to type in freeform text. The Choice prompt will automatically reprompt until a choice or synonym is chosen.

The RecognizerOptions NoValue and/or NoAction appear to be related to this, but I haven't been able to find good documentation on them. Setting them to true doesn't work.

AddDialog(new ChoicePrompt(promptForChoice) { RecognizerOptions = new FindChoicesOptions() { NoValue = true, NoAction = true } });

I've also tried creating an "anything" validator that always returns true.

AddDialog(new ChoicePrompt(promptForChoice, validator: AnythingValidator.AnythingValidatorAsync) { RecognizerOptions = new FindChoicesOptions() { NoValue = true, NoAction = true } });
public static Task<bool> AnythingValidatorAsync(PromptValidatorContext<FoundChoice> promptContext, CancellationToken cancellationToken)
    {           
        return Task.FromResult(true);
    }

This allows the prompt to exit, but the result is null. I can go dig out what the user entered from the Context.Activity.Text but that doesn't seem like a very robust solution.

There seems to be something obvious I'm missing with PromptChoice


Solution

  • Choices work by hardcoding in the options the user needs to choose from. We can't implement freeform text in choices. What you can do is, add another choice "others" in the choice list and implement a waterfall to get the user input. Also, you can't use the RecognizerOptions as they are related to synonyms.