示例#1
0
        public async Task Ask_Product(DialogContext dialogContext, IDictionary <string, object> args, SkipStepFunction next)
        {
            await dialogContext.Context.SendActivity(new Activity
            {
                Type = ActivityTypes.Typing
            });

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

            userState.EntitiesState = new EntitiesState
            {
                EntitiesParse      = entities,
                AddedDate          = DateTime.Now,
                DrinksQuantityUsed = 0,
                PizzasQuantityUsed = 0
            };

            if (entities.Ingredients.Count > 0)
            {
                List <Pizza> pizzas = EntitieRecomendation.GetPizzasByIngredients(entities.Ingredients, context);
                pizzas = pizzas.Skip(quantityPizza * userState.EntitiesState.PizzasQuantityUsed).ToList();

                List <Attachment> attachments = GetPizzaAttachments(pizzas, userState);
                userState.EntitiesState.PizzasQuantityUsed++;

                IMessageActivity messageActivity = MessageFactory.Carousel(attachments);
                await dialogContext.Context.SendActivity($"Estou lhe enviando as pizzas disponíveis, começando pelas pizzas que possuem {GetIngredientsFindedText(pizzas, entities.Ingredients)}");

                await dialogContext.Context.SendActivity(new Activity
                {
                    Type = ActivityTypes.Typing
                });

                Thread.Sleep(4000);
                await dialogContext.Context.SendActivity(messageActivity);
            }
            else if (entities.Drinks.Count > 0)
            {
                List <Drink> drinks = EntitieRecomendation.GetDrinksMoreSalesWithUserDrinks(userState.EntitiesState.EntitiesParse.Drinks, context);

                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("Estou lhe enviando as bebidas disponíveis, começando pelas solicitadas");

                await dialogContext.Context.SendActivity(new Activity
                {
                    Type = ActivityTypes.Typing
                });

                Thread.Sleep(4000);
                await dialogContext.Context.SendActivity(messageActivity);
            }
            else if (entities.ProductTypes.Count > 0)
            {
                if (entities.ProductTypes.Where(x => x == "pizza").ToList().Count > 0)
                {
                    List <Pizza> pizzas = EntitieRecomendation.GetPizzasByIngredients(userState.EntitiesState.EntitiesParse.Ingredients, context);
                    pizzas = pizzas.Skip(quantityPizza * userState.EntitiesState.PizzasQuantityUsed).ToList();

                    List <Attachment> attachments = GetPizzaAttachments(pizzas, userState);
                    userState.EntitiesState.PizzasQuantityUsed++;

                    IMessageActivity messageActivity = MessageFactory.Carousel(attachments);
                    await dialogContext.Context.SendActivity("Estou lhe enviando as pizzas disponíveis, ordenando pelas mais vendidas");

                    await dialogContext.Context.SendActivity(new Activity
                    {
                        Type = ActivityTypes.Typing
                    });

                    Thread.Sleep(4000);
                    await dialogContext.Context.SendActivity(messageActivity);
                }
                else if (entities.ProductTypes.Where(x => x == "bebida").ToList().Count > 0)
                {
                    List <Drink> drinks = EntitieRecomendation.GetDrinksMoreSalesWithUserDrinks(userState.EntitiesState.EntitiesParse.Drinks, context);

                    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("Estou lhe enviando as bebidas disponíveis, ordenando pelas mais vendidas");

                    await dialogContext.Context.SendActivity(new Activity
                    {
                        Type = ActivityTypes.Typing
                    });

                    Thread.Sleep(4000);
                    await dialogContext.Context.SendActivity(messageActivity);
                }
            }
            else
            {
                List <Pizza> pizzas = EntitieRecomendation.GetPizzasMoreSales(context);
                pizzas = pizzas.Skip(quantityPizza * userState.EntitiesState.PizzasQuantityUsed).ToList();

                List <Attachment> attachments = GetPizzaAttachments(pizzas, userState);
                userState.EntitiesState.PizzasQuantityUsed++;

                IMessageActivity messageActivity = MessageFactory.Carousel(attachments);
                await dialogContext.Context.SendActivity("Estou lhe enviando as pizzas disponíveis, ordenando pelas mais vendidas");

                await dialogContext.Context.SendActivity(new Activity
                {
                    Type = ActivityTypes.Typing
                });

                Thread.Sleep(2000);
                await dialogContext.Context.SendActivity(messageActivity);
            }
        }
示例#2
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);
            }
        }