Exemplo n.º 1
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());
        }
Exemplo n.º 2
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);
        }