C# Bot框架:提示和重试提示消息同时出现
我向用户显示了一个提示,其中包含提示消息和重试提示消息,请参见以下内容:C# Bot框架:提示和重试提示消息同时出现,c#,botframework,bots,prompt,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),
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);
当我在emulator中运行BOT时,提示消息和重试提示消息同时出现,我不希望出现这种情况,请参见以下内容:
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.cs类中的以下代码调用cancel对话框
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);
}
}
公共类取消对话框:ComponentDialog
{
公共只读BotDialogSet-DialogSet;
私有常量字符串CancelWaterAllDialogs=“CancelWaterAllDialogs”;
私有常量字符串CancelCurrentDialogsPrompt=“CancelCurrentDialogsPrompt”;
public CancelDialog(BotDialogSet dialogSet):基本(名称(CancelDialog))
{
DialogSet=DialogSet;
var waterwallsteps=新的waterwallstep[]
{
你想取消吗,
完成选定操作
};
AddDialog(新建WaterWallDialog(取消WaterWallDialogs,WaterWallSteps));
AddDialog(新建确认提示符(CancelCurrentDialogsPrompt));
}
私有静态异步任务将需要取消(WaterWallStepContext ctx,CancellationToken CancellationToken)
{
返回等待ctx.PromptAsync(CancelCurrentDialogsPrompt,新建PromptOptions
{
Prompt=MessageFactory.Text(“您确定要取消吗?”),
RetryPrompt=MessageFactory.Text(“您确定要取消吗?请选择或键入是/否”)
},取消令牌);
}
专用静态异步任务完成者选择操作(WaterWallStepContext ctx,CancellationToken CancellationToken)
{
如果((bool)ctx.Result)
{
等待ctx.Parent.CancelAllDialogsAsync(cancellationToken);
返回wait ctx.EndBotDialogAsync(cancellationToken);
}
return wait 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);
}
private TaskYorNValidator(PromptValidatorContext promptContext,CancellationToken CancellationToken)
{
//测试值…并通过true或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);
}
private static async Task将需要取消(waterwallstepcontext ctx,CancellationToken CancellationToken)
{
var选项=新的提示选项
{
Prompt=MessageFactory.Text(“您确定要取消吗?”),
RetryPrompt=MessageFactory.Text(“您确定要取消吗?请选择或键入是/否”)
},取消令牌);
返回wait wait stepContext.PromptAsync(“YNValidator”、选项、取消令牌);
}
我想我已经解决了您的问题,但我刚刚尝试了您的代码,它实际上运行正常。所以,你能给我一点关于你在哪里尝试的细节吗?这样我就可以重现你的问题。你的问题的答案是肯定的,你的理解是正确的。但我猜你的意思是问如何解决你的问题,所以我不会简单地用“是”作为回答。为了澄清发生了什么,听起来你好像在说“你确定要取消吗?”和重试提示“请选择或键入是/否”在第一次遇到提示时,这两个消息都作为单独的消息发送。但是在那之后的转弯处会发生什么呢?如果用户发送了无法识别的选项,会发生什么情况?如果用户的选择被认可,会发生什么?请在Emulator中发布消息的屏幕截图,这样我们就可以对您的对话流程有一个清晰的印象。@KyleDelaney我编辑了这篇文章,以包含一个屏幕截图并回答您的一些问题。感谢您为我指出确认提示的方向,这是我错过的东西。我会实施这个,然后看看问题是否还在发生。你的想法是正确的。我已经用canceldialog类中的代码更新了帖子