繁体   English   中英

Botframework V4:对话框

[英]Botframework V4: Dialogs

从我从文档中读到的 BeginDialogAsync 就像从堆栈中推送,而 EndDialogAsync 就像从堆栈中弹出一样。 但它在我的代码中并没有那样的行为。

当我按回结束对话框 3 中的对话框时,它返回对话框 1 而不是对话框 2。它是否应该 go 回到对话框 2,因为 EndDialogAsync 弹出对话框 3? 有人可以帮我解释一下 BeginDialogAsync、EndDialogAsync、ContinueDialogAsync、ReplaceDialogAsync、NextAsync 的 function。 谢谢

对话 1

    AddStep(async (stepContext, cancellationToken) =>
        {
            var choices = new[] { "Opportunities!" };
            return await stepContext.PromptAsync(
                "choicePrompt",
                new PromptOptions
                {
                    Prompt = MessageFactory.Text($"What can i do for you?"),
                    Choices = ChoiceFactory.ToChoices(choices),
                });
        });

        AddStep(async (stepContext, cancellationToken) =>
        {
            var response = (stepContext.Result as FoundChoice)?.Value;

            if (response == "Opportunities!")
            {
                return await stepContext.BeginDialogAsync(MainLookAtOppurtinitiesDialog.Id, cancellationToken: cancellationToken);
            }
        });

由对话框 1 的 BeginDialogAsync 调用的对话框 2

  AddStep(async (stepContext, cancellationToken) =>
        {
            var choices = new[] { "Real Estate", "Mutual Funds" };
            return await stepContext.PromptAsync(
                "choicePrompt",
                new PromptOptions
                {
                    Prompt = MessageFactory.Text($"So {state.Name}, Here are your choices:"),
                    Choices = ChoiceFactory.ToChoices(choices),
                });
        });

        AddStep(async (stepContext, cancellationToken) =>
        {
            var response = (stepContext.Result as FoundChoice)?.Value;

            if (response == "Real Estate")
            {
                return await stepContext.BeginDialogAsync(MainRealEstateDialog.Id, cancellationToken: cancellationToken);
            }

            if (response == "Mutual Funds")
            {
                return await stepContext.BeginDialogAsync(MainMutualFundsDialog.Id, cancellationToken: cancellationToken);
            }

            return await stepContext.ContinueDialogASync();
        });

Dialog 2 的 BeginDialogAsync 调用的 Dialog 3

        AddStep(async (stepContext, cancellationToken) =>
        {
            var choices = new[] { "Continue", "Back" };
            return await stepContext.PromptAsync(
                "choicePrompt",
                new PromptOptions
                {
                    Prompt = MessageFactory.Text("Real Estate is what most people invest in first. While deemed a safe investment, please still be wary of factors like: Location, Taxes and Current state of the Economy."),
                    Choices = ChoiceFactory.ToChoices(choices),
                    RetryPrompt = MessageFactory.Text($"Please choose one of the options."),
                },
                cancellationToken);
        });

        AddStep(async (stepContext, cancellationToken) =>
        {
            var response = (stepContext.Result as FoundChoice)?.Value;

            if (response == "Continue")
            {
                return await stepContext.NextAsync();
            }
            else if (response == "Back")
            {
                return await stepContext.EndDialogAsync();
            }
            else
            {
                return await stepContext.ReplaceDialogAsync(MainRealEstateDialog.Id);
            }
        });

选择返回时,它会返回对话框 1 而不是对话框 2。

编辑:这是整个代码以及如何将其添加到对话框上下文中。

    public class CalculateMonthlyAmortizations : WaterfallDialog
    {
        public CalculateMonthlyAmortizations(string dialogId, IEnumerable<WaterfallStep> steps = null)
            : base(dialogId, steps)
        {
           AddStep(async (stepContext, cancellationToken) =>
          {
             //..
          });
        }
        public static string Id => "calculateMonthlyAmortizationDialog";

        public static CalculateMonthlyAmortizations Instance { get; } = new CalculateMonthlyAmortizations(Id);
    }
}

        _dialogs = new DialogSet(dialogState);
        _dialogs.Add(CalculateMonthlyAmortizations.Instance);

以防万一其他人有同样的问题,听起来您的 Dialog 2 没有实现 ResumeDialofAsync 来捕获来自 Dialog 3 的返回。在这种情况下,返回汇总到下一个父级,即 Dialog 1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM