问题描述
我最近正在使用Microsoft的botframework开发聊天机器人.我正在使用hint.confirm接受用户的是/否输入,但是当我编写基本的是/否时,它显示了太多尝试异常.我不希望我的机器人显示过多尝试异常,而是希望在内部处理它.这是我的代码.
I was recently developing a chatbot using Microsoft's botframework. I am using prompt.confirm to take user's yes/no input but it shows too many attempts exception when I write basic yes/no. I don't want my bot to display too many attempts exception instead I want to handle it internally. Here's my code.
[LuisIntent("None")]
public async Task NoneIntent(IDialogContext context, LuisResult result)
{
try
{
PromptDialog.Confirm(context, NextQuestionAsync, QuestionPrompt, attempts: 1, promptStyle: PromptStyle.Auto);
}
catch (Exception ex)
{
await context.PostAsync("Something really bad happened.");
}
}
public async Task NextQuestionAsync(IDialogContext context, IAwaitable<bool> result)
{
try
{
if (await result)
{
await context.PostAsync($"Ok, alarm 0 disabled.");
//context.Wait(NoneIntent);
}
else
{
await context.PostAsync("You Said No");
}
}
catch (Exception e)
{
}
}
推荐答案
感谢ezequiel,我通过重写PromptOptions构造函数解决了此问题.我使用PromptDialog.Choice实现了它,但是我也可以通过确认来完成它.这就是我所做的
I resolved this issue by overriding the PromptOptions constructor, Thanks to ezequiel. I used PromptDialog.Choice to achieve it however I could also have done it with confirm. Here's what I did
List<string> questions = new List<string>();
questions.Add("Yes"); // Added yes option to prompt
questions.Add("No"); // Added no option to prompt
string QuestionPrompt = "Are you sure?";
PromptOptions<string> options = new PromptOptions<string>(QuestionPrompt, "", "", questions, 1); // Overrided the PromptOptions Constructor.
PromptDialog.Choice<string>(context, NextQuestionAsync, options);
这篇关于C#BotFramework Prompt.Confirm显示太多尝试异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!