我可以向Bot Framework PromptDialog添加自定义逻辑来处理无效答案吗? [英] Can I add custom logic to a Bot Framework PromptDialog for handling invalid answers?

查看:99
本文介绍了我可以向Bot Framework PromptDialog添加自定义逻辑来处理无效答案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Bot Framework项目中,我使用PromptDialog来显示一组预定义的有效选项,并带有以下代码:

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?

推荐答案

此问题可能有两个有效答案:

There are likely two valid answers for this question:

  1. 如果要更改验证,可以从PromptChoice继承并覆盖TryParseMessageReceivedAsync方法.例如, CancelablePromptChoice
  2. 在处理诸如帮助之类的全局命令时,您可能要考虑使用Scorables,而不是像我在#1中解释的那样进行操作.查看 GlobalMessagesHandlers 示例以了解更多信息
  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.

这篇关于我可以向Bot Framework PromptDialog添加自定义逻辑来处理无效答案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆