MicrosoftBot v4中的ConfirmPrompt无法设置重试次数。
从MicrosoftBot Framework v3可以理解,我们可以选择设置“尝试”以重试对话框。但是我没有在v4中看到类似的功能。该文档没有提供相同的说明。
private async Task<DialogTurnResult> Step2Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var opts = new PromptOptions
{
Prompt = MessageFactory.Text("Do you want to continue the conversation?"),
RetryPrompt = MessageFactory.Text("Sorry, I did not understand. Do u want me to continue this conversation?"),
};
return await stepContext.PromptAsync("ConfirmPrompt", opts, cancellationToken);
}
private async Task<DialogTurnResult> Step3Async(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var selectedchoice = (stepContext.Result as FoundChoice).Value;
selectedchoice = (selectedchoice as string).ToLower();
if (selectedchoice.Contains("yes"))
{
await stepContext.Context.SendActivityAsync(selectedchoice);
}
else if (selectedchoice.Contains("no"))
{
await stepContext.Context.SendActivityAsync(selectedchoice);
} else
{
// I will find the Intent through LUIS to understand what the User is trying to say.
}
return await stepContext.EndDialogAsync();
}
当前,重试选项是无限制的尝试,除非用户从给定列表中进行选择,否则对话框不会退出。
我希望将“重试”选项限制为2次,然后退出/结束对话框。
答案 0 :(得分:0)
我查看了Bot Builder(.Net版本)here的来源,尤其是在Prompts
部分,看来我找不到tooManyAttempts
您提到的Bot v3中存在的异常。
对于感兴趣的人,在v3(sources)中看起来像这样:
protected virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> message)
{
T result;
if (this.TryParse(await message, out result))
{
context.Done(result);
}
else
{
--promptOptions.Attempts;
if (promptOptions.Attempts >= 0)
{
await context.PostAsync(this.MakePrompt(context, promptOptions.Retry ?? promptOptions.DefaultRetry, promptOptions.Choices?.Keys.ToList().AsReadOnly(), promptOptions.Descriptions, promptOptions.RetrySpeak ?? promptOptions.DefaultRetrySpeak));
context.Wait(MessageReceivedAsync);
}
else
{
//too many attempts, throw.
await context.PostAsync(this.MakePrompt(context, promptOptions.TooManyAttempts));
throw new TooManyAttemptsException(promptOptions.TooManyAttempts);
}
}
}
正如您在第4版Github的问题和承诺中所看到的那样,最近有一些有关此问题的讨论/工作:
numberOfAttemps
:https://github.com/Microsoft/botbuilder-dotnet/pull/1774 numberOfAttemps
字段:https://github.com/Microsoft/botbuilder-js/pull/870 因此,使用此字段,您应该能够在“停止重试策略”上实现自己的逻辑