public async Task StartAsync(IDialogContext context) { var sender = new SendCorrectYesOrNoCard(context); await sender.Send(MessagesResource.AskIfWantSuggestions); new HandleUserIncorrectInput(context).ResetCounter(); context.Wait(GetTask); }
public async Task GetTask(IDialogContext context, IAwaitable <IMessageActivity> result) { var userResponse = await result; var luisResult = await LuisHelper.GetIntentAndEntitiesFromLUIS(userResponse.Text); switch (luisResult.TopScoringIntent.Intent) { case LuisIntent.Yes: { await context.PostAsync(MessagesResource.AddOtherProducts); context.Call(_dialogFactory.Create <GetProductsByUserTask>(), Callback); break; } case LuisIntent.No: { context.Call(_dialogFactory.Create <AskIfWantSuggestionProductsTask>(), Callback); break; } default: { var handler = new HandleUserIncorrectInput(context); if (handler.CheckCounterErrors()) { await handler.UserErrorLimitExceeded(); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } else { await context.PostAsync(MessagesResource.CourtesyChooseError); var sender = new SendCorrectYesOrNoCard(context); await sender.Send(MessagesResource.AskIfWantAddProduct); context.Wait(GetTask); } break; } } }
public async Task GetTask(IDialogContext context, IAwaitable <IMessageActivity> result) { try { var userResponse = await result; var luisResult = await LuisHelper.GetIntentAndEntitiesFromLUIS(userResponse.Text); var recommendationResult = new RecommendationDto() { Matcher = new MatcherResponse() { Results = new List <MatcherItem>() { new MatcherItem() { Id = 3034, Raw = "pasta", Score = 0.6, Type = "Category" }, new MatcherItem() { Id = 3034, Raw = "pizza", Score = 0.6, Type = "Category" }, new MatcherItem() { Id = 3034, Raw = "vino", Score = 0.6, Type = "Category" } } }, Products = new List <ProductDto>() { new ProductDto() { CategoryId = 3034, Description = "prodotto 1", Id = 1, SKU = "1" }, new ProductDto() { CategoryId = 3034, Description = "prodotto 2", Id = 2, SKU = "2" }, new ProductDto() { CategoryId = 3034, Description = "prodotto 3", Id = 3, SKU = "3" }, new ProductDto() { CategoryId = 3034, Description = "prodotto 4", Id = 4, SKU = "4" } } }; context.UserData.SetValue("LastRecommendationProducts", recommendationResult.Products); context.UserData.SetValue("LastRecommendationMatcher", recommendationResult.Matcher); switch (luisResult.TopScoringIntent.Intent) { case LuisIntent.Yes: { if (recommendationResult.Products.Count > minSuggestionProductNumber) { context.Call(_dialogFactory.Create <GetSuggestionProductByCardTask>(), Callback); } else { await context.PostAsync(MessagesResource.NoSuggestionProduct); context.Call(_dialogFactory.Create <GetPromoProductByCardTask>(), Callback); } break; } case LuisIntent.No: { context.Call(_dialogFactory.Create <AskIfWantProductPositionTask>(), Callback); break; } default: { var handler = new HandleUserIncorrectInput(context); if (handler.CheckCounterErrors()) { await handler.UserErrorLimitExceeded(); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } else { await context.PostAsync(MessagesResource.CourtesyChooseError); var sender = new SendCorrectYesOrNoCard(context); await sender.Send(MessagesResource.AskIfWantSuggestions); context.Wait(GetTask); } break; } } } catch (Exception ex) { await context.PostAsync(MessagesResource.CourtesyError); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } }
public async Task GetTask(IDialogContext context, IAwaitable <IMessageActivity> result) { try { var userResponse = await result; var channel = context.Activity.ChannelId; var shoppingListId = context.UserData.GetValue <Guid>("CurrentShoppingListId"); var shoppingItems = new List <ShoppingItemDto>() { new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "pasta", Id = context.UserData.Get <Guid>("CurrentShoppingListId") }, new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "vino", Id = context.UserData.Get <Guid>("CurrentShoppingListId") }, new ShoppingItemDto() { CategoryId = 3034, Color = Pin.Gray, Description = "pizza", Id = context.UserData.Get <Guid>("CurrentShoppingListId") } }; var luisResult = await LuisHelper.GetIntentAndEntitiesFromLUIS(userResponse.Text); var showLabel = false; switch (luisResult.TopScoringIntent.Intent) { case LuisIntent.Yes: case LuisIntent.No: { if (luisResult.TopScoringIntent.Intent == LuisIntent.Yes) { showLabel = true; switch (channel) { case "facebook": var facebookSender = new SendFacebookTemplate(context); var imageFacebookTemplate = new ImageFacebookTemplate($"image.jpeg", false).GetTemplate(); await facebookSender.Send(imageFacebookTemplate); break; default: var defaultSender = new SendCardToConversation(context); var imageCard = new ImageCard($"image.jpeg"); await defaultSender.SendCard(imageCard); break; } } if (shoppingItems.Count == 0) { await context.PostAsync(MessagesResource.EmptyShoppingList); } else { await context.PostAsync(MessagesResource.ShowShoppingListReview); var sb = new StringBuilder(); foreach (var item in shoppingItems) { var label = $"{(!string.IsNullOrEmpty(item.Label) ? "[" + item.Label + "] " : string.Empty)}"; sb.Append($"{(showLabel ? label : string.Empty)}{item.Description}" + "\n\n"); } await context.PostAsync(sb.ToString()); } context.Call(_dialogFactory.Create <OpeningHoursDialog>(), Callback); break; } default: { var handler = new HandleUserIncorrectInput(context); if (handler.CheckCounterErrors()) { await handler.UserErrorLimitExceeded(); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } else { await context.PostAsync(MessagesResource.CourtesyChooseError); var sender = new SendCorrectYesOrNoCard(context); await sender.Send(MessagesResource.AskIfWantSeePosition); context.Wait(GetTask); } break; } } } catch (Exception ex) { await context.PostAsync(MessagesResource.CourtesyError); context.Call(_dialogFactory.Create <GreetingDialog>(), Callback); } }