Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

c# - Can I add custom logic to a Bot Framework PromptDialog for handling invalid answers?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are likely two valid answers for this question:

  1. If you want to change the validation, you can inherit from the PromptChoice and override the TryParse or the MessageReceivedAsync methods. For example, the CancelablePromptChoice
  2. 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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...