Bot Framework v4.0:无法在对话框中执行瀑布步骤

时间:2018-09-27 07:59:17

标签: .net botframework

我正在尝试创建一个根对话框,用户可以在其中选择两个选项。每个选项都会将用户重新引导到对话框。问题是我在对话框构造器中创建了瀑布步骤,但从未执行过。

我的根对话框中的代码是:

 public class GreetingDialog : ComponentDialog
    {
        // User state for greeting dialog
        private const string GreetingStateProperty = "greetingState";

        // Dialog IDs
        private const string ProfileDialog = "profileDialog";
        private static readonly List<string> _welcomeList = new List<string> { "All", "Typed" };

        public static IList<Choice> WelcomeChoices { get; } = ChoiceFactory.ToChoices(_welcomeList);

        // <summary>Gets the reprompt action for the top-level dialog.</summary>
        public static Activity WelcomeReprompt
        {
            get
            {
                var reprompt = MessageFactory.SuggestedActions(_welcomeList, "Please choose an option");
                reprompt.AttachmentLayout = AttachmentLayoutTypes.List;
                return reprompt as Activity;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GreetingDialog"/> class.
        /// </summary>
        /// <param name="botServices">Connected services used in processing.</param>
        /// <param name="botState">The <see cref="UserState"/> for storing properties at user-scope.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> that enables logging and tracing.</param>
        public GreetingDialog(ILoggerFactory loggerFactory)
            : base(nameof(GreetingDialog))
        {
            // Add control flow dialogs
            var waterfallSteps = new WaterfallStep[]
            {
                    InitializeStateStepAsync,
                    DisplayGreetingStateStepAsync,
            }; 
            AddDialog(new WaterfallDialog(ProfileDialog, waterfallSteps));
            AddDialog(new ChoicePrompt("choicePrompt"));
        }

        private async Task<DialogTurnResult> InitializeStateStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Greet the guest and ask them to choose an option.
            await stepContext.Context.SendActivityAsync(
                "Welcome to Contoso Hotel and Resort.",
                cancellationToken: cancellationToken);
            return await stepContext.PromptAsync(
                "choicePrompt",
                new PromptOptions
                {
                    Prompt = MessageFactory.Text("Choose an option"),
                    RetryPrompt = WelcomeReprompt,
                    Choices = WelcomeChoices,
                },
                cancellationToken);
        }

        private async Task<DialogTurnResult> DisplayGreetingStateStepAsync(
                                                    WaterfallStepContext stepContext,
                                                    CancellationToken cancellationToken)
        {
            var context = stepContext.Context;

            // Display their profile information and end dialog.
            await context.SendActivityAsync($"end of greeting dialog!");
            return await stepContext.EndDialogAsync();
        }
    }

我无法确定如何执行瀑布步骤或如何获得选择结果。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您没有实现运行机器人所需的OnTurnAsync方法。看看this sample,您需要在转弯内执行以下操作:

var dialogContext = await _dialogs.CreateContextAsync(turnContext, cancellationToken);
var results = await dialogContext.ContinueDialogAsync(cancellationToken);

if (results.Status == DialogTurnStatus.Empty)
{
    await dialogContext.BeginDialogAsync("details", null, cancellationToken);
}