【发布时间】:2019-09-24 19:20:32
【问题描述】:
我正在向用户显示一个提示,其中包含提示消息和重试提示消息,见下文:
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);
}
}
【问题讨论】:
-
我以为我解决了你的问题,但我只是尝试了你的代码,它实际上运行正常。那么你能否提供更多关于你在哪里尝试这个的细节,以便我可以重现你的问题。
-
你的问题的答案是肯定的,你的理解是正确的。但既然我猜你的意思是问如何解决你的问题,我不会简单地发布“是”作为答案。
-
为了澄清发生了什么,听起来你在说提示“你确定要取消吗?”和重试提示“请选择或键入是/否”在遇到提示的第一轮时都作为单独的消息发送。但是在那之后的转弯会发生什么?如果用户发送了一个无法识别的选择会发生什么?如果用户的选择被识别会发生什么?请在模拟器中发布消息的屏幕截图,以便我们对您的对话流程有一个明确的印象。
-
@KyleDelaney 我已经编辑了帖子以包含屏幕截图并回答您的一些问题。感谢您向我指出确认提示的方向,这是我错过的东西。我将执行此操作,然后查看问题是否仍然存在
-
你的想法是正确的。我已经用我的 canceldialog 类中的代码更新了帖子
标签: c# botframework bots prompt