public async Task Sugestao(IDialogContext context, LuisResult result) { var entity = result?.Entities?.Where(x => x.Type == "categoria").FirstOrDefault()?.Entity?.ToString(); Category category = Category.anyway; if (!String.IsNullOrEmpty(entity)) { category = (Category)Enum.Parse(typeof(Category), entity); } var movieService = new TheMovieDBService(); if (botMovieTipsService == null) { botMovieTipsService = new BotMovieTipsService(); } await botMovieTipsService.ConfigureAuthentication(); var favoriteMedias = await botMovieTipsService.GetFavoriteMedias(userId); if (favoriteMedias.Count == 0) { await context.PostAsync($@"Aaah, ainda não te conheço o suficiente para conseguir te indicar um filme que vc goste! ¯\_(⊙︿⊙)_/¯"); await context.PostAsync($@"Você pode me pedir criticas sobre filmes / serie e falar quais você gosta pra eu aprender mais sobre você S2"); return; } int random = new Random().Next(favoriteMedias.Count); var favoriteMediaChoiced = favoriteMedias[random]; var mediasRecommendated = await movieService.GetRecommendation(favoriteMediaChoiced.IdMedia, EnumExtensions.GetDescription(category)); var msg = context.MakeMessage(); msg.AttachmentLayout = AttachmentLayoutTypes.Carousel; foreach (var media in mediasRecommendated) { var card = new CardPersonalizedService().CreateCard(media); msg.Attachments.Add(card.ToAttachment()); } await context.PostAsync(msg); //Implementar Form @Migg //FormDialog<Form.Sugestao> sugestionForm = new FormDialog<Form.Sugestao>(new Form.Sugestao(), Form.Sugestao.BuildForm, FormOptions.PromptInStart); //context.Call(sugestionForm, SugestaoFormCompleteAsync); }
protected override async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result) { var answer = result.Answers.FirstOrDefault(); if (answer != null) { var question = answer.Questions.FirstOrDefault(); TheMovieDBService movieService = new TheMovieDBService(); var media = await movieService.GetMediaByName(question.ToString(), category); if (media != null) { var card = new CardPersonalizedService().CreateCard(media); var msg = context.MakeMessage(); msg.Attachments.Add(card.ToAttachment()); await context.PostAsync(msg); context.Done(message); } } }