private async Task Salutation(DialogContext dialogContext, IDictionary <string, object> args, SkipStepFunction next)
        {
            BotUserState userState = UserState <BotUserState> .Get(dialogContext.Context);

            if (string.IsNullOrEmpty(userState.Status))
            {
                dialogContext.ActiveDialog.State = new Dictionary <string, object>();
                await dialogContext.Context.SendActivity("Olá, seja bem vindo a Pergher Pizzaria!!!");

                await dialogContext.Context.SendActivity($"Eu sou o Jorge {Emojis.ManRaisingHand} o bot da Pergher pizzaria. Estou aqui para te ajudar em seu pedido.  \n" +
                                                         $"Dúvidas? Digite *AJUDA* e será encaminhado ao manual de utilização.  \n" +
                                                         $"Problemas em alguma parte da conversa? Digite *SAIR* e voltaremos ao fluxo normal.");

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

                await dialogContext.Prompt(TextPrompt, "Como você está se sentindo hoje?");
            }
            else
            {
                await dialogContext.Context.SendActivity(new Activity
                {
                    Type = ActivityTypes.Typing
                });

                await dialogContext.Context.SendActivity($"Olá, é um prazer ter você aqui {Emojis.SmileHappy}  \nO que você gostaria hoje? ");

                await dialogContext.End();
            }
        }
예제 #2
0
        private PizzaModel AddPizzaOrder(string id, string size, BotUserState userState)
        {
            PizzaModel pizzaModelFind = userState.OrderModel.Pizzas.Where(x => x.PizzaId == int.Parse(id) && x.SizeName == size).FirstOrDefault();

            if (pizzaModelFind != null)
            {
                pizzaModelFind.Quantity++;
                userState.OrderModel.PriceTotal += pizzaModelFind.Price;
                return(pizzaModelFind);
            }
            else
            {
                Pizza     pizza     = context.Pizzas.Where(x => x.PizzaId == int.Parse(id)).FirstOrDefault();
                PizzaSize pizzaSize = context.Pizzas.Include(x => x.PizzaIngredients).ThenInclude(y => y.Ingredient)
                                      .Include(x => x.PizzaSizes).ThenInclude(y => y.SizeP).FirstOrDefault().PizzaSizes.Where(x => x.SizeP.Size == size).FirstOrDefault();

                PizzaModel pizzaModel = new PizzaModel
                {
                    PizzaId   = pizza.PizzaId,
                    PizzaName = pizza.Name,
                    SizeId    = pizzaSize.SizePId,
                    SizeName  = pizzaSize.SizeP.Size,
                    Quantity  = 1,
                    Price     = pizzaSize.Price
                };
                userState.OrderModel.Pizzas.Add(pizzaModel);
                userState.OrderModel.PriceTotal += (pizzaModel.Quantity * pizzaModel.Price);
                return(pizzaModel);
            }
        }
예제 #3
0
        private DrinkModel AddDrinkOrder(string id, string quantity, BotUserState userState)
        {
            DrinkModel drinkModelFind = userState.OrderModel.Drinks.Where(x => x.DrinkId == int.Parse(id) && x.DrinkQuantity == double.Parse(quantity)).FirstOrDefault();

            if (drinkModelFind != null)
            {
                drinkModelFind.Quantity++;
                userState.OrderModel.PriceTotal += drinkModelFind.Price;
                return(drinkModelFind);
            }
            else
            {
                Drink     drink     = context.Drinks.Where(x => x.DrinkId == int.Parse(id)).Include(x => x.DrinkSizes).ThenInclude(y => y.SizeD).FirstOrDefault();
                DrinkSize drinkSize = drink.DrinkSizes
                                      .Where(x => x.SizeD.Quantity == double.Parse(quantity)).FirstOrDefault();


                DrinkModel drinkModel = new DrinkModel
                {
                    DrinkId       = drink.DrinkId,
                    DrinkName     = drink.Name,
                    DrinkQuantity = drinkSize.SizeD.Quantity,
                    Quantity      = 1,
                    DrinkSizeName = drinkSize.SizeD.SizeName,
                    Price         = drinkSize.Price
                };

                userState.OrderModel.Drinks.Add(drinkModel);
                userState.OrderModel.PriceTotal += (drinkModel.Quantity * drinkModel.Price);
                return(drinkModel);
            }
        }
예제 #4
0
        private List <Attachment> GetDrinkAttachments(List <Drink> drinks, BotUserState userState)
        {
            List <Attachment> attachments = new List <Attachment>();

            foreach (var drink in drinks.Take(quantityDrink))
            {
                attachments.Add(new ThumbnailCard
                {
                    Title   = drink.Name,
                    Images  = new CardImage[] { new CardImage(url: ServerUrl + @"/" + drink.Image) },
                    Buttons = drink.DrinkSizes.Select(x => new CardAction
                    {
                        Type  = ActionTypes.PostBack,
                        Title = x.SizeD.SizeName + " ( R$ " + x.Price.ToString("F") + ")",
                        Value = drink.DrinkId + "||" + x.SizeD.Quantity + "||" + ActionTypes.PostBack + "AddDrink"
                    }).ToList()
                }.ToAttachment());
            }

            if (drinks.Count > quantityDrink * userState.EntitiesState.DrinksQuantityUsed)
            {
                attachments.Add(new HeroCard
                {
                    Buttons = new List <CardAction>
                    {
                        new CardAction {
                            Title = "Mais bebidas", Value = ActionTypes.PostBack + "MoreDrink", Type = ActionTypes.PostBack
                        }
                    }
                }.ToAttachment());
            }
            return(attachments);
        }
        private async Task How_Is(DialogContext dialogContext, IDictionary <string, object> args, SkipStepFunction next)
        {
            BotUserState userState = UserState <BotUserState> .Get(dialogContext.Context);

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

            await dialogContext.Prompt(TextPrompt, "Eu estou ótimo e você, como está se sentindo hoje?");
        }
        private async Task Answer_How_Is(DialogContext dialogContext, IDictionary <string, object> args, SkipStepFunction next)
        {
            dialogContext.ActiveDialog.State["status"] = args["Value"];

            BotUserState userState = UserState <BotUserState> .Get(dialogContext.Context);

            userState.Status = Convert.ToString(dialogContext.ActiveDialog.State["status"]);

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

            await dialogContext.Context.SendActivity($"Eu estou ótimo {Emojis.SmileHappy}!  \nO que você gostaria hoje?");

            await dialogContext.End();
        }
예제 #7
0
        private async Task Ask_StatusBegin(DialogContext dialogContext, IDictionary <string, object> args, SkipStepFunction next)
        {
            await dialogContext.Context.SendActivity(new Activity
            {
                Type = ActivityTypes.Typing
            });

            BotUserState userState = UserState <BotUserState> .Get(dialogContext.Context);

            User user = context.Users.Where(x => x.UserIdBot == dialogContext.Context.Activity.From.Id).FirstOrDefault();

            List <Order> orders = context.Orders.Where(x => x.User.UserId == user.UserId).ToList();

            if (orders.Count > 0)
            {
                IActivity activity = MessageFactory.Carousel(GetAttachmentsByOrders(orders));
                await dialogContext.Context.SendActivity(activity);
            }
            else
            {
                await dialogContext.Context.SendActivity("Você não possui nenhum pedido em aberto no momento!  \n O que você gostaria hoje?");
            }
        }
예제 #8
0
        private List <Attachment> GetPizzaAttachments(List <Pizza> pizzas, BotUserState userState)
        {
            List <Attachment> attachments = new List <Attachment>();

            foreach (var pizza in pizzas.Take(quantityPizza))
            {
                string ingredients = GetIngredientsString(pizza.PizzaIngredients);

                attachments.Add(new ThumbnailCard
                {
                    Title    = pizza.Name,
                    Subtitle = pizza.PizzaType,
                    Text     = ingredients,
                    Images   = new CardImage[] { new CardImage(url: ServerUrl + @"/" + pizza.Image) },
                    Buttons  = pizza.PizzaSizes.Select(x => new CardAction
                    {
                        Type  = ActionTypes.PostBack,
                        Title = x.SizeP.Size + " ( R$ " + x.Price.ToString("F") + ")",
                        Value = pizza.PizzaId + "||" + x.SizeP.Size + "||" + ActionTypes.PostBack + "AddPizza"
                    }).ToList()
                }.ToAttachment());
            }

            if (pizzas.Count > quantityPizza * userState.EntitiesState.PizzasQuantityUsed)
            {
                attachments.Add(new HeroCard
                {
                    Buttons = new List <CardAction>
                    {
                        new CardAction {
                            Title = "Mais Pizzas", Value = ActionTypes.PostBack + "MorePizza", Type = ActionTypes.PostBack
                        }
                    }
                }.ToAttachment());
            }
            return(attachments);
        }
예제 #9
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);
            }
        }
예제 #10
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);
            }
        }
예제 #11
0
        public async Task OnTurn(ITurnContext turnContext)
        {
            /*if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate && turnContext.Activity.MembersAdded.FirstOrDefault()?.Id == turnContext.Activity.Recipient.Id)
             * {
             *  await turnContext.SendActivity($"Seja bem vindo a Pergher pizzaria {Emojis.SmileHappy}");
             *
             *  await turnContext.SendActivity(new Activity
             *  {
             *      Type = ActivityTypes.Typing
             *  });
             *
             *  await turnContext.SendActivity($"Eu sou o Jorge o bot da Pergher pizzaria e estou aqui para auxiliá-lo no seu pedido {Emojis.SmileHappy} \n" +
             *      "Atualmente eu posso realizar as seguintes tarefas: \n" +
             *      "*-Ofereço bebidas e pizzas cutomizadas na sua solicitação* \n" +
             *      "*-Mostro como seu carrinho está no momento* \n" +
             *      "*-Limpo seu carrinho quando solicitado* \n" +
             *      "*-Finalizo seu carrinho quando solicitado* \n" +
             *      "*-Edito e removo itens seu carrinho quando solicitado* \n" +
             *      "*-Edito seu endreço de entrega atual quando solicitado* \n" +
             *      "*-Busco seus pedidos abertos para saber o seu estado* \n");
             *
             *  await turnContext.SendActivity($"Quando tiver alguma dúvida simplesmente escreva *AJUDA* e lhe redirecionarei para exemplos de uso {Emojis.SmileHappy}\n" +
             *      $"Caso queira sair de uma conversa que esteja no momento, simplesmente digite *SAIR* e voltaremos ao fluxo normal da conversa {Emojis.SmileHappy}\n" +
             *      $"Em que lhe posso ser útil no momento?");
             *
             * }*/

            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                var           dialogState   = turnContext.GetConversationState <Dictionary <string, object> >();
                DialogContext dialogContext = DialogFlow.CreateContext(turnContext, dialogState);

                if (turnContext.Activity.Text.ToLower() == "sair")
                {
                    dialogContext.EndAll();
                }
                else if (turnContext.Activity.Text.ToLower() == "ajuda")
                {
                    //IActivity activity = MessageFactory.SuggestedActions(new CardAction[]
                    //    {
                    //        new CardAction
                    //        {
                    //            Title = "Abrir documentação",
                    //            Type = ActionTypes.OpenUrl,
                    //            Value = "https://pizzeria-bot-tc.readthedocs.io/pt/latest/index.html"
                    //        }
                    //    });

                    IActivity activity = MessageFactory.Attachment(new HeroCard
                    {
                        Buttons = new List <CardAction>
                        {
                            new CardAction
                            {
                                Title = "Abrir manual",
                                Type  = ActionTypes.OpenUrl,
                                Value = "https://pizzeria-bot-tc.readthedocs.io/pt/latest/index.html"
                            }
                        }
                    }.ToAttachment());

                    await dialogContext.Context.SendActivity($"Clique no botão abaixo para abrir o manual {Emojis.SmileHappy} ");

                    await dialogContext.Context.SendActivity(activity);
                }
                else
                {
                    await dialogContext.Continue();

                    BotUserState userState = UserState <BotUserState> .Get(dialogContext.Context);

                    if (!turnContext.Responded)
                    {
                        RecognizerResult luisResult   = turnContext.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);
                        string           intentResult = LuisResult.GetLuisIntent(luisResult, userState);

                        IDictionary <string, object> args = new Dictionary <string, object>
                        {
                            { "entities", EntitiesParse.RecognizeEntities(luisResult.Entities) }
                        };

                        await dialogContext.Begin(intentResult, args);
                    }
                }
            }
            else if (turnContext.Activity.Type != ActivityTypes.ConversationUpdate)
            {
                await turnContext.SendActivity($"Olá, ainda não estou preparado para tratar este tipo de informacão {Emojis.SmileSad}  \n" +
                                               $"Peço que utilize apenas texto para melhorar nossa interação {Emojis.SmileHappy}");
            }
        }