我有选择的提示,我想让它这样即使用户键入别的,与选择的同义词对话框仍然可以继续前进。我试图这样做,但它不工作。
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);
}
一个选项提示有通过比较选择列表,对话框将不会继续进行,直到有效的输入提供验证用户输入。你试图验证在下一步的输入,但下一步将无法达成,直至输入电压已经验证,这就是为什么textResponse
绝不会“好”或“确定”。
幸运的是,选择提示有一个内置在每一个选择提供同义词的方法。代替
Choices = ChoiceFactory.ToChoices(choices),
你可以这样做
Choices = new List<Choice>
{
new Choice
{
Value = "Agree",
Synonyms = new List<string>
{
"Okay",
"OK",
},
},
},