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

时间:2019-05-07 07:11:24

标签: c# botframework bots prompt

我有一条提示要显示给用户,其中包含提示消息并重试提示消息,请参见下文:

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);

当我在模拟器中运行BOT时,提示消息和重试提示消息同时出现,这是我不希望发生的,请参见下文:

Multiple prompts

当我输入错误的选项时,重试提示将按预期显示。从列表中选择正确的值后,对话将按预期进行,没有错误的对话框。

---更新---

我正在使用bot.cs类中的以下代码调用取消对话框

await dialogContext.BeginDialogAsync(nameof(CancelDialog));

在调用它时,对话框堆栈上没有任何内容。这是我的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 个答案:

答案 0 :(得分:1)

1-定义以下内容:

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

-在以下位置添加它:

  AddDialog(new ConfirmPrompt(CancelCurrentDialogsPrompt));

2-定义YesOrNValidator:

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

3-下一步,重写WouldYouLikeToCancel

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);
    }