[英]Bot Framework: Prompt and retry prompt messages appear at the same time
我有一个向用户显示的提示,其中包含提示消息和重试提示消息,请参见下文:
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 时,提示信息和重试提示信息同时出现,这是我不希望发生的,见下文:
当我输入不正确的选项时,重试提示按预期显示。 从列表中选择正确的值后,对话会按预期继续,没有错误的对话。
- - 更新 - -
我正在使用 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-定义以下内容:
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-接下来重写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.