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); } }
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}"); } }