问题
In my Bot Framework project, I'm using a PromptDialog to show a predefined set of valid options, with the below code:
var pickListOptions = new List<Option>();
pickListOptions.AddRange(
_currentQuestion.validValues.Select(x => Option.CreateOption(x)));
PromptDialog.Choice(context, choiceSelected,
pickListOptions,
_currentQuestion.label,
"Sorry, I didn't get that", 3, PromptStyle.Keyboard);
When a free-form answer is typed in which is not in the list of valid values is entered, the "Sorry, I didn't get that" message is automatically displayed and the question is reprompted. However, I want to potentially handle certain invalid answers with a different dialog (i.e. if the user is asking for help). Is there any way to override the automatic reprompt with custom logic?
回答1:
There are likely two valid answers for this question:
- If you want to change the validation, you can inherit from the
PromptChoice
and override theTryParse
or theMessageReceivedAsync
methods. For example, the CancelablePromptChoice - For handling global commands, like help, instead of doing what I explained in #1, you might want to consider using
Scorables
. Take a look to the GlobalMessagesHandlers sample to understand more.
来源:https://stackoverflow.com/questions/44704544/can-i-add-custom-logic-to-a-bot-framework-promptdialog-for-handling-invalid-answ