Пример #1
0
        private async static void Listen(string sanitizedText, ITweet tweet)
        {
            try
            {
                Console.WriteLine($"Searched: {sanitizedText}");
                var intent = await languageAnalyzer.AnalyzeAsync(sanitizedText);

                if (intent.Name == "BuscaTitulo")
                {
                    var omdbRequest = new OmbdRequest()
                    {
                        Title = intent.Entities["Titulo"]
                    };
                    var movie = await meDaUmFilmeSearch.GetMovie(omdbRequest);

                    var replyText = $"Found: {movie.Title} from {movie.Year}";
                    Console.WriteLine(replyText);
                    await ReplyToTweet(tweet, replyText, movie.Poster);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unmanaged error:\n" + ex.ToString());
            }
        }
Пример #2
0
        public async Task <Movie> GetMovie(OmbdRequest request)
        {
            var movie = new Movie();

            var response = await client.GetAsync(request.SearchUri);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                var omdbResult = Newtonsoft.Json.JsonConvert.DeserializeObject <OmdbResult>(result);

                return(omdbResult.Search.FirstOrDefault());
            }

            return(movie);
        }