Bot Framework v4.Как получить значение внутри, если еще в диалоговом окне шага водопада и передать его на следующий шаг? - PullRequest
0 голосов
/ 03 января 2019

Как получить значение внутри, если еще в диалоговом окне шага водопада и передать его на следующий шаг? Пожалуйста, обратитесь к коду ниже, спасибо. Спасибо за любую помощь, спасибо.

ОБНОВЛЕНИЕ: выбор «Рядом со мной» работает нормально, но при выборе «Где-то еще» возникает ошибка.

 AddStep(async (stepContext, cancellationToken) =>
        {
            var realEstateType = stepContext.Result as FoundChoice;
            var state = await (stepContext.Context.TurnState["FPBotAccessors"] as FPBotAccessors).FPBotStateAccessor.GetAsync(stepContext.Context);
            state.RealEstateType = realEstateType.Value;

            return await stepContext.PromptAsync("choicePrompt",
               new PromptOptions
               {
                   Prompt = stepContext.Context.Activity.CreateReply("Which location are you considering?"),
                   Choices = new[] {new Choice {Value = "Near me"},
                                    new Choice {Value = "Somewhere else"}
                   }.ToList()
               });

        });

        AddStep(async (stepContext, cancellationToken) => 
        {
            var nearOrSomewhereElse = stepContext.Result as FoundChoice;
            var state = await (stepContext.Context.TurnState["FPBotAccessors"] as FPBotAccessors).FPBotStateAccessor.GetAsync(stepContext.Context);
            state.NearOrSomewhereElse = nearOrSomewhereElse.Value;

            var value = "";

            if (state.NearOrSomewhereElse == "Somewhere else")
            {
                await stepContext.PromptAsync("textPrompt",
                new PromptOptions
                {
                    Prompt = stepContext.Context.Activity.CreateReply("Which location are you considering?")
                });

                value = stepContext.Result as string; // i think this is the error. How can i get the result of the block of code inside this if block?
            }
            else if (state.NearOrSomewhereElse == "Near me")
            {
                value = "Near me";
            }

            return await stepContext.NextAsync(value, cancellationToken);

        });



        AddStep(async (stepContext, cancellationToken) =>
        {
            var nearOrSomewhereElse = stepContext.Result as string;
            var state = await (stepContext.Context.TurnState["FPBotAccessors"] as FPBotAccessors).FPBotStateAccessor.GetAsync(stepContext.Context);
            state.NearOrSomewhereElse = nearOrSomewhereElse;

            return await stepContext.PromptAsync("choicePrompt",
             new PromptOptions
                 {
                   Prompt = stepContext.Context.Activity.CreateReply($"Please indicate the size of {state.RealEstateType}"),
                   Choices = new[] {new Choice {Value = "Size 1"},
                                    new Choice {Value = "Size 2"},
                                    new Choice {Value = "Size 3"}
                   }.ToList()
             });                    

        });
enter code here

1 Ответ

0 голосов
/ 03 января 2019

Самый простой способ сделать это - использовать API WaterfallStepContext::NextAsync, передав значение, на которое вы хотите перейти, на следующий шаг, который затем будет доступен для следующего шага через свойство WaterfallStepContext::Result.

Это будет выглядеть примерно так:

   // Your first step elided for brevity

   AddStep(async (stepContext, cancellationToken) =>
   {
            var nearOrSomewhereElse = stepContext.Result as FoundChoice;
            var state = await (stepContext.Context.TurnState["FPBotAccessors"] as FPBotAccessors).FPBotStateAccessor.GetAsync(stepContext.Context);
            state.NearOrSomewhereElse = nearOrSomewhereElse.Value;

            if (state.NearOrSomewhereElse == "Near me")
            {
               value = "Near me";
            }
            else if (state.NearOrSomewhereElse == "Somewhere else")
            {
               //prompt user. user's answer will be stored to value.
                value = "User input";
            }

            // Call NextAsync passing on the value
            return await stepContext.NextAsync(value, cancellationToken);
   });

   AddStep(async (stepContext, cancellationToken) =>
   {
         // Retrieve the result of the previous step
         var x = stepContext.Result as string;

         // … use the value here …
   });
...