首页 > 解决方案 > 返回任务中的对话框

问题描述

我在任务功能中有特定的对话框。有没有办法在不退出瀑布步骤的情况下返回任务中的某个对话框。

谢谢

我试过 cs.ActiveDialog.State["stepIndex"] = (int)cs.ActiveDialog.State["stepIndex"] -1; 返回到上一个对话框状态,但它执行下一个瀑布对话框

标签: c#botframework

解决方案


在这种情况下,最常见的方法是用自身替换当前对话框,为每个瀑布步骤添加逻辑,以确定它是否应该执行或直接进入下一步。例如,您应该在对话框选项中设置要执行的步骤索引,然后检查是否在执行每个步骤时设置了该值。

例如,这里的瀑布步骤的简化版本可能如下所示;

当您想返回上一步时,您可以使用;

            return await sc.ReplaceDialogAsync(YourCurrentDialogID, new YourCurrentDialog(stepIndexToGoBackTo));

然后在每个瀑布步骤中,您可以检查您是否指定了要跳回的特定步骤,如果没有,它会按顺序执行每个步骤。


        public async Task<DialogTurnResult> PromptUser(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var stepToExecute = sc.Options as int?;

            if(!stepToExecute.HasValue || (stepToExecute.HasValue && stepToExecute.Value == sc.Index)
{
    // either we haven't set a specific step to run, so we will execute anyway
    // or we have specified a step to run and the index matches, so we conditionally execute
}

// a step index has been passed into the options, but it doesn't match the current step
// so drop through until we hit the right step.
return await sc.NextAsync();
}

请原谅上面的代码,它可能不完全符合,但应该是正确的。我在手机上写这个:)


推荐阅读