简体   繁体   English

Bot Framework:提示和重试提示信息同时出现

[英]Bot Framework: Prompt and retry prompt messages appear at the same time

I have a prompt that I'm displaying to the user that contains a prompt message and retry prompt message, see below:我有一个向用户显示的提示,其中包含提示消息和重试提示消息,请参见下文:

return await ctx.PromptAsync(CancelCurrentDialogsPrompt, new PromptOptions
{
    Prompt = MessageFactory.Text("Are you sure you'd like to cancel?"),
    Choices = ChoiceFactory.ToChoices(confirmationOptionsList),
    RetryPrompt = MessageFactory.Text("Please select or type yes/no")
}, cancellationToken);

When I run the BOT in the emulator, the prompt message and the retry prompt message appear at the same time, which I'm not expecting to happen, see below:当我在模拟器中运行 BOT 时,提示信息和重试提示信息同时出现,这是我不希望发生的,见下文:

多重提示

When I enter in a incorrect option, the retry prompt shows as expected.当我输入不正确的选项时,重试提示按预期显示。 After selecting a correct value from the list the conversation continues as expected, with no incorrect dialogs.从列表中选择正确的值后,对话会按预期继续,没有错误的对话。

--- UPDATE --- - - 更新 - -

I'm calling the cancel dialog using the following code from my bot.cs class我正在使用 bot.cs 类中的以下代码调用取消对话框

await dialogContext.BeginDialogAsync(nameof(CancelDialog));

When it is being called there is nothing on the dialog stack.当它被调用时,对话框堆栈上没有任何内容。 Here is the code in my CancelDialog.cs这是我的 CancelDialog.cs 中的代码

public class CancelDialog : ComponentDialog
    {
        public readonly BotDialogSet DialogSet;

        private const string CancelWaterfallDialogs = "CancelWaterfallDialogs";
        private const string CancelCurrentDialogsPrompt = "CancelCurrentDialogsPrompt";

        public CancelDialog(BotDialogSet dialogSet) : base(nameof(CancelDialog))
        {
            DialogSet = dialogSet;

            var waterfallSteps = new WaterfallStep[]
            {
                WouldYouLikeToCancel,
                CompleteUsersSelectedAction
            };

            AddDialog(new WaterfallDialog(CancelWaterfallDialogs, waterfallSteps));
            AddDialog(new ConfirmPrompt(CancelCurrentDialogsPrompt));
        }

        private static async Task<DialogTurnResult> WouldYouLikeToCancel (WaterfallStepContext ctx, CancellationToken cancellationToken)
        {
            return await ctx.PromptAsync(CancelCurrentDialogsPrompt, new PromptOptions
            {
                Prompt = MessageFactory.Text("Are you sure you'd like to cancel?"),
                RetryPrompt = MessageFactory.Text("Are you sure you'd like to cancel? Please select or type yes/no")
            }, cancellationToken);
        }

        private static async Task<DialogTurnResult> CompleteUsersSelectedAction(WaterfallStepContext ctx, CancellationToken cancellationToken)
        {
            if ((bool)ctx.Result)
            {
                await ctx.Parent.CancelAllDialogsAsync(cancellationToken);
                return await ctx.EndBotDialogAsync(cancellationToken);
            }

            return await ctx.EndDialogAsync(cancellationToken: cancellationToken);
        }
    }

1- define the following: 1-定义以下内容:

 AddDialog(new TextPrompt("YNValidator", YesNoValidator);

-add it after: - 在后面添加:

  AddDialog(new ConfirmPrompt(CancelCurrentDialogsPrompt));

2- define YesOrNValidator: 2- 定义 YesOrNValidator:

private Task<bool>YorNValidator (PromptValidatorContext<string> promptContext, CancellationToken cancellationToken)
{
  //Test the value... and pass true or false
    Task.FromResult(true);
 }

3- Next REWRITE the WouldYouLikeToCancel 3-接下来重写WillYouLikeToCancel

private static async Task<DialogTurnResult> WouldYouLikeToCancel (WaterfallStepContext ctx, CancellationToken cancellationToken)
    {
        var options= new PromptOptions
        {
            Prompt = MessageFactory.Text("Are you sure you'd like to cancel?"),
            RetryPrompt = MessageFactory.Text("Are you sure you'd like to cancel? Please select or type yes/no")
        }, cancellationToken);
    return await stepContext.PromptAsync("YNValidator",options,cancellationToken);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM