Пример #1
0
        private async Task <DialogTurnResult> PromptForCityStepAsync(
            WaterfallStepContext stepContext,
            CancellationToken cancellationToken)
        {
            // Save name if prompted for
            var greetingState = await GreetingStateAccessor.GetAsync(stepContext.Context, () => new GreetingState());

            var args = stepContext.Result as string;

            if (!string.IsNullOrWhiteSpace(args) && string.IsNullOrWhiteSpace(greetingState.Name))
            {
                greetingState.Name = args;
            }

            // Prompt for city if missing
            if (string.IsNullOrWhiteSpace(greetingState.City))
            {
                var options = new PromptOptions
                {
                    Prompt = new Activity
                    {
                        Type = ActivityTypes.Message,
                        Text = $"What city do you live in?",
                    },
                };
                return(await stepContext.PromptAsync(nameof(CityPrompt), options, cancellationToken));
            }
            else
            {
                return(await stepContext.NextAsync());
            }
        }
Пример #2
0
        private async Task <DialogTurnResult> DisplayGreetingStateStepAsync(
            WaterfallStepContext stepContext,
            CancellationToken cancellationToken)
        {
            // Save city if it were prompted.
            var greeting = await GreetingStateAccessor.GetAsync(stepContext.Context, () => new GreetingState());

            var args = stepContext.Result as string;

            if (string.IsNullOrWhiteSpace(greeting.City) && !string.IsNullOrWhiteSpace(args))
            {
                greeting.City = args;
                await GreetingStateAccessor.SetAsync(stepContext.Context, greeting);

                await stepContext.Context.SendActivityAsync($"Ok `{greeting.Name}`, I've got you living in `{greeting.City}`.");

                await stepContext.Context.SendActivityAsync("I'll go ahead an update your profile with that information.");
            }
            else
            {
                await stepContext.Context.SendActivityAsync($"Hi `{greeting.Name}`, living in `{greeting.City}`,"
                                                            + " I understand greetings and asking for help!  Or start your connection over for a card.");
            }

            return(await stepContext.EndDialogAsync());
        }
Пример #3
0
        private async Task <DialogTurnResult> InitializeStateStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var greetingState = await GreetingStateAccessor.GetAsync(stepContext.Context, () => new GreetingState());

            stepContext.Values[NameValue] = greetingState.Name;
            stepContext.Values[CityValue] = greetingState.City;

            return(await stepContext.NextAsync());
        }
Пример #4
0
        // Handle updates to entities.
        protected override async Task <bool> ProcessUpdateEntitiesAsync(JObject entities, DialogContext dc, CancellationToken cancellationToken)
        {
            var greetingState = await GreetingStateAccessor.GetAsync(dc.Context, () => new GreetingState());

            // Supported LUIS Entities
            string[] userNameEntities     = { "userName", "userName_paternAny" };
            string[] userLocationEntities = { "userLocation", "userLocation_patternAny" };

            var result = false;

            if (entities != null && entities.HasValues)
            {
                // Update any entities
                foreach (var name in userNameEntities)
                {
                    // check if we found valid slot values in entities returned from LUIS
                    if (entities[name] != null)
                    {
                        greetingState.Name = (string)entities[name][0];
                        result             = true;
                        break;
                    }
                }

                foreach (var city in userLocationEntities)
                {
                    if (entities[city] != null)
                    {
                        greetingState.City = (string)entities[city][0];
                        result             = true;
                        break;
                    }
                }

                // set the new values
                await GreetingStateAccessor.SetAsync(dc.Context, greetingState);
            }

            return(result);
        }