private async Task ProcessNextStep(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next)
        {
            var catalogFilter  = dc.Context.GetUserState <UserInfo>().CatalogFilter;
            var selectedAction = (args["Activity"] as Activity)?.Text?.Trim();

            dynamic activityResponse;

            try
            {
                activityResponse = JsonConvert.DeserializeObject(selectedAction);
            } catch (Exception ex)
            {
                await dc.Context.SendActivity("I didn't understand your response. Please click on a button");

                await dc.Replace(Id);

                return;
            }
            if (activityResponse.ActionType == BotActionTypes.Back)
            {
                await dc.Context.SendActivity("Type what do you want to do.");

                await dc.End();
            }
            //else if (activityResponse.ActionType == BotActionTypes.CatalogFilter)
            //{
            //    await dc.Replace(CatalogFilterDialog.Id);
            //}
            else
            {
                catalogFilter.PageIndex++;
                await dc.Replace(Id);
            }
        }
示例#2
0
        private async Task ValidateBrandStep(DialogContext dc, IDictionary <string, object> args, SkipStepFunction next)
        {
            var userState = dc.Context.GetUserState <UserInfo>();

            if (dc.Context.Activity.AttachmentContainsImageFile())
            {
                await catalogFilterDialogService.UpdateCatalogFilterUserStateWithTagsAsync(dc.Context);

                await dc.Replace(CatalogDialog.Id);
            }
            else
            {
                var selectedBrand = (args["Activity"] as Activity)?.Text?.Trim();
                var brands        = dc.ActiveDialog.State[BrandsCacheKey] as IEnumerable <Models.Catalog.Brand>;

                if (brands.Select(b => b.Text).Contains(selectedBrand))
                {
                    userState.CatalogFilter.Brand = selectedBrand;
                    await dc.Replace(PromptTypes);
                }
                else
                {
                    await dc.Context.SendActivity("I didn't understand your response. Please select one brand.");

                    await dc.Replace(Id);
                }
            }
        }
示例#3
0
 public async Task AnswerOrderProducts(DialogContext dialogContext, IDictionary <string, object> args, SkipStepFunction next)
 {
     await dialogContext.Replace(Order_Product_Waterfall_Text, args);
 }
示例#4
0
        public async Task OrderProducts(DialogContext dialogContext, IDictionary <string, object> args, SkipStepFunction next)
        {
            await dialogContext.Context.SendActivity(new Activity
            {
                Type = ActivityTypes.Typing
            });

            Activity     activity  = (Activity)args["Activity"];
            BotUserState userState = UserState <BotUserState> .Get(dialogContext.Context);

            List <Pizza> pizzas = EntitieRecomendation.GetPizzasByIngredients(userState.EntitiesState.EntitiesParse.Ingredients, context);

            if (userState.EntitiesState.EntitiesParse.Ingredients.Count == 0)
            {
                pizzas = EntitieRecomendation.GetPizzasMoreSales(context);
            }
            List <Drink> drinks = EntitieRecomendation.GetDrinksMoreSalesWithUserDrinks(userState.EntitiesState.EntitiesParse.Drinks, context);

            if (activity.Text.Contains(ActionTypes.PostBack + "AddPizza"))
            {
                string[]   productData = activity.Text.Split("||");
                PizzaModel pizzaModel  = AddPizzaOrder(productData[0], productData[1], userState);
                userState.EntitiesState.PizzasQuantityUsed--;

                await dialogContext.Context.SendActivity($"A pizza {pizzaModel.PizzaName} - {pizzaModel.SizeName} foi adicionada com sucesso {Emojis.SmileHappy}");

                await dialogContext.Context.SendActivity($"Gostaria de ver mais alguma pizza?  \nClique no botão caso deseje, ou simplesmente solicite o que deseja {Emojis.SmileHappy})");

                await dialogContext.Context.SendActivity(GetSuggestedActionsNewsPizzasAndDrinks("Pizza"));
            }
            else if (activity.Text.Contains(ActionTypes.PostBack + "SuggestedActionPizza"))
            {
                pizzas = pizzas.Skip(quantityPizza * userState.EntitiesState.PizzasQuantityUsed).ToList();
                List <Attachment> attachments = GetPizzaAttachments(pizzas, userState);
                userState.EntitiesState.PizzasQuantityUsed++;
                IMessageActivity activitySend = MessageFactory.Carousel(attachments);
                await dialogContext.Context.SendActivity(activitySend);
            }
            else if (activity.Text == (ActionTypes.PostBack + "MorePizza"))
            {
                pizzas = pizzas.Skip(quantityPizza * userState.EntitiesState.PizzasQuantityUsed).ToList();
                List <Attachment> attachments = GetPizzaAttachments(pizzas, userState);
                userState.EntitiesState.PizzasQuantityUsed++;
                IMessageActivity activitySend = MessageFactory.Carousel(attachments);
                await dialogContext.Context.SendActivity(activitySend);
            }
            else if (activity.Text.Contains(ActionTypes.PostBack + "AddDrink"))
            {
                string[]   productData = activity.Text.Split("||");
                DrinkModel drinkModel  = AddDrinkOrder(productData[0], productData[1], userState);
                userState.EntitiesState.DrinksQuantityUsed--;

                await dialogContext.Context.SendActivity($"{drinkModel.DrinkName} {drinkModel.DrinkSizeName} adicionado com sucesso {Emojis.SmileHappy}");

                await dialogContext.Context.SendActivity($"Gostaria de ver mais alguma bebida?  \nClique no botão caso deseje, ou simplesmente solicite o que deseja {Emojis.SmileHappy}");

                await dialogContext.Context.SendActivity(GetSuggestedActionsNewsPizzasAndDrinks("Drink"));
            }
            else if (activity.Text.Contains(ActionTypes.PostBack + "SuggestedActionDrink"))
            {
                drinks = drinks.Skip(quantityDrink * userState.EntitiesState.DrinksQuantityUsed).ToList();
                List <Attachment> attachments = GetDrinkAttachments(drinks, userState);
                userState.EntitiesState.DrinksQuantityUsed++;
                IMessageActivity activitySend = MessageFactory.Carousel(attachments);
                await dialogContext.Context.SendActivity(activitySend);
            }
            else if (activity.Text == (ActionTypes.PostBack + "MoreDrink"))
            {
                drinks = drinks.Skip(quantityDrink * userState.EntitiesState.DrinksQuantityUsed).ToList();
                List <Attachment> attachments = GetDrinkAttachments(drinks, userState);
                userState.EntitiesState.DrinksQuantityUsed++;
                IMessageActivity messageActivity = MessageFactory.Carousel(attachments);
                await dialogContext.Context.SendActivity(messageActivity);
            }
            else
            {
                RecognizerResult luisResult   = dialogContext.Context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);
                string           intentResult = LuisResult.GetLuisIntent(luisResult, userState);

                IDictionary <string, object> createdArgs = new Dictionary <string, object>
                {
                    { "entities", EntitiesParse.RecognizeEntities(luisResult.Entities) }
                };
                await dialogContext.Replace(intentResult, createdArgs);
            }
        }