在 Microsoft Bot v4 中设置 ConfirmPrompt 的尝试次数

Set number of attempts to ConfirmPrompt in Microsoft Bot v4

MicrosoftBot v4 中的 ConfirmPrompt 无法设置重试的次数。

根据 MicrosoftBot Framework v3 的理解,我们可以选择设置 'attempts' 以重试对话框。但是我在 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 次,然后退出/结束对话框。

我查看了 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);
        }
    }
}

正如您在 v4 Github 的问题和提交中看到的那样,最近有一些关于此的讨论/工作:

所以有了这个字段,你应该能够在 "stopping retries policy"

上实现你自己的逻辑