作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试创建一个对话框,在其中定义多个瀑布步骤。在此对话框的上下文中,有时我需要根据用户的选择返回到之前的瀑布步骤。我找到了这个方法:
await stepContext.ReplaceDialogAsync("Name of the dialog");
然而,这个方法重新执行整个对话框,这不是我需要的。
事实上,我创建的瀑布步骤是三个:
我的代码是:
public class ListAllCallsDialog : ComponentDialog
{
// Dialog IDs
private const string ProfileDialog = "ListAllCallsDialog";
/// <summary>
/// Initializes a new instance of the <see cref="ListAllCallsDialog"/> class.
/// </summary>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> that enables logging and tracing.</param>
public ListAllCallsDialog(ILoggerFactory loggerFactory)
: base(nameof(ListAllCallsDialog))
{
// Add control flow dialogs
var waterfallSteps = new WaterfallStep[]
{
ListAllCallsDialogSteps.ChoiceCallStepAsync,
ListAllCallsDialogSteps.ShowCallStepAsync,
ListAllCallsDialogSteps.EndDialog,
};
AddDialog(new WaterfallDialog(ProfileDialog, waterfallSteps));
AddDialog(new ChoicePrompt("cardPrompt"));
}
/// <summary>
/// Contains the waterfall dialog steps for the main dialog.
/// </summary>
private static class ListAllCallsDialogSteps
{
static int callListDepth = 0;
static List<string> Calls;
public static async Task<DialogTurnResult> ChoiceCallStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
await stepContext.Context.SendActivityAsync(
"Right now i'm in list all calls dialog",
cancellationToken: cancellationToken);
GetAllCalls();
return await stepContext.PromptAsync("cardPrompt", GenerateOptions(stepContext.Context.Activity, callListDepth), cancellationToken);
}
public static async Task<DialogTurnResult> ShowCallStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
// Get the text from the activity to use to show the correct card
var text = stepContext.Context.Activity.Text.ToLowerInvariant();
if(text == "Show older")
//Go back to the first step
else if(text == "Show earlier")
//Go back to the first step
else
await stepContext.Context.SendActivityAsync(
"The call you choose is : " + text.ToString(),
cancellationToken: cancellationToken);
return await stepContext.ContinueDialogAsync();
}
public static async Task<DialogTurnResult> EndDialog(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
await stepContext.Context.SendActivityAsync(
"Getting back to the parent Dialog",
cancellationToken: cancellationToken);
return await stepContext.EndDialogAsync(null, cancellationToken);
}
/// <summary>
/// Creates options for a <see cref="ChoicePrompt"/> so the user may select an option.
/// </summary>
/// <param name="activity">The message activity the bot received.</param>
/// <returns>A <see cref="PromptOptions"/> to be used in a prompt.</returns>
/// <remarks>Related type <see cref="Choice"/>.</remarks>
private static PromptOptions GenerateOptions(Activity activity, int callListDepth)
{
// Create options for the prompt
var options = new PromptOptions()
{
Prompt = activity.CreateReply("Please choose a call from the list below"),
Choices = new List<Choice>(),
};
for(int i=10*callListDepth; i <= 10 * (callListDepth + 1); i++)
{
if (Calls.ElementAtOrDefault(i) != null)
options.Choices.Add(new Choice() { Value = Calls[i] });
}
options.Choices.Add(new Choice() { Value = "Show older" });
if(callListDepth!=0)
options.Choices.Add(new Choice() { Value = "Show earlier" });
return options;
}
private static void GetAllCalls()
{
//List of all calls found
for (int i = 0; i < 30; i++)
Calls.Add("Call" + i.ToString());
}
}
有人可以告诉我怎么做吗?
最佳答案
我不确定这样做是否正确且有效,但您可以尝试使用 State
context.ActiveDialog
的属性(property)在你的Task<DialogTurnResult>
功能。
context.ActiveDialog.State["stepIndex"] = (int)context.ActiveDialog.State["stepIndex"] -2;
关于c# - Bot framework v4.0 如何在对话中执行前面的瀑布步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52554441/
我正在为我的网格样式显示使用 jQuery 瀑布。 为了解决常见的图像重叠问题,我将瀑布方法包装在 .load() 函数中,例如: $(window).load(function(){ $('#b
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 3年前关闭。 Improve thi
对于瀑布图,如果设置为 isSum() ,是否有办法覆盖列标签上显示的值,不幸的是,每列传递的值都会四舍五入,因此会出现当最后一列设置为 isSum() 时,与 Excel 数据相比存在差异。 最佳答
我是一名优秀的程序员,十分优秀!