Botframework V4:用户键入响应而不是单击选择提示按钮

问题描述 投票:0回答:1

我有选择的提示,我想让它这样即使用户键入别的,与选择的同义词对话框仍然可以继续前进。我试图这样做,但它不工作。

public class InitialQuestions : WaterfallDialog
{
    public InitialQuestions(string dialogId, IEnumerable<WaterfallStep> steps = null)
        : base(dialogId, steps)
    { 

        AddStep(async (stepContext, cancellationToken) =>
        {
            var choices = new[] { "Agree" };
            return await stepContext.PromptAsync(
                "choicePrompt",
                new PromptOptions
                {
                    Prompt = MessageFactory.Text(string.Empty),
                    Choices = ChoiceFactory.ToChoices(choices),
                    RetryPrompt = MessageFactory.Text("Click Agree to proceed."),
                });
        });

        AddStep(async (stepContext, cancellationToken) =>
        {
            var response = (stepContext.Result as FoundChoice).Value.ToLower();
            var textResponse = (stepContext.Result as FoundChoice).ToString().ToLower();

            if (response == "agree" || textResponse == "okay" || textResponse == "ok")
            {
                return await stepContext.NextAsync();
            }
            else
            {
                return await stepContext.ReplaceDialogAsync(InitialQuestions.Id);
            }
        });
    }

    public static string Id => "initialQuestions";

    public static InitialQuestions Instance { get; } = new InitialQuestions(Id);
}
c# botframework
1个回答
0
投票

一个选项提示有通过比较选择列表,对话框将不会继续进行,直到有效的输入提供验证用户输入。你试图验证在下一步的输入,但下一步将无法达成,直至输入电压已经验证,这就是为什么textResponse绝不会“好”或“确定”。

幸运的是,选择提示有一个内置在每一个选择提供同义词的方法。代替

Choices = ChoiceFactory.ToChoices(choices),

你可以这样做

Choices = new List<Choice>
{
    new Choice
    {
        Value = "Agree",
        Synonyms = new List<string>
        {
            "Okay",
            "OK",
        },
    },
},
© www.soinside.com 2019 - 2024. All rights reserved.