public async Task <SportsResponse> GetSportsAsync() { string urlPath = "/v1/sports"; HttpResponseMessage result = this.GetHttpResponseAsync(urlPath).Result; string content = await result.Content.ReadAsStringAsync(); SportsResponse sportsResponse = JsonConvert.DeserializeObject <SportsResponse>(content); return(sportsResponse); }
public virtual IAliceResponseBase Fallback(SportsRequest sportsRequest) { var buttons = new List <AliceButtonModel>() { new SportsButtonModel(Sports_Resources.Command_LatestNews), new SportsButtonModel(Sports_Resources.Command_MainNews), new SportsButtonModel(Sports_Resources.Command_BestComments) }; var response = new SportsResponse(sportsRequest, Sports_Resources.Help_Text_Tts, buttons); response.SessionState.CurrentScene = SceneType; return(response); }
public override IAliceResponseBase Reply(SportsRequest sportsRequest) { var buttons = new List <AliceButtonModel>() { new SportsButtonModel(Sports_Resources.Command_LatestNews), new SportsButtonModel(Sports_Resources.Command_MainNews), new SportsButtonModel(Sports_Resources.Command_BestComments) }; var response = new SportsResponse(sportsRequest, Sports_Resources.Welcome_Text, buttons); response.SessionState.CurrentScene = SceneType; return(response); }
public override IAliceResponseBase Reply(SportsRequest sportsRequest) { SportsResponse response; var fromDate = DateTimeOffset.Now.AddDays(-1); NewsArticleModel newsArticle = null; if (sportsRequest.State.Session.NextNewsArticleId != Guid.Empty) { newsArticle = _newsService.GetById(sportsRequest.State.Session.NextNewsArticleId); } if (newsArticle == null) { newsArticle = _newsService.GetPopularNews(fromDate, new PagedRequest(1, 0)).Items.FirstOrDefault(); } IEnumerable <NewsArticleCommentModel> comments = null; if (newsArticle != null) { comments = _newsArticleCommentService.GetBestComments(newsArticle.Id, _sportsSettings.CommentsToDisplay); } if (comments != null && comments.Any()) { var buttons = new List <AliceButtonModel>() { new AliceButtonModel() { Title = Sports_Resources.Command_BestComments_OpenNewsArticle, Url = newsArticle.Url, Hide = false } }; string ttsEnding = string.Empty; var nextNewsArticle = _newsService.GetNextPopularNewsArticle(fromDate, newsArticle.Id); Guid nextNewsArticleId = Guid.Empty; if (nextNewsArticle != null) { ttsEnding = $"{AliceHelper.SilenceString500}{Sports_Resources.Tips_BestComments_Next}"; buttons.Add(new SportsButtonModel(Sports_Resources.Command_BestComments_Next)); nextNewsArticleId = nextNewsArticle.Id; } buttons.Add(new SportsButtonModel(Sports_Resources.Command_LatestNews)); buttons.Add(new SportsButtonModel(Sports_Resources.Command_MainNews)); var text = new StringBuilder($"{Sports_Resources.BestComments_Title_Tts} \"{newsArticle.Title} {GetTitleEnding(newsArticle)}\":"); var tts = new StringBuilder($"{Sports_Resources.BestComments_Title_Tts} \"{newsArticle.Title}\"{AliceHelper.SilenceString500}"); foreach (var comment in comments) { string textComment = $"\n\n{EmojiLibrary.SpeechBalloon} {comment.CommentText} {EmojiLibrary.ThumbsUp}{comment.CommentRating}"; string textTts = $"{AliceHelper.SilenceString500}{comment.CommentText}"; if (text.Length + textComment.Length <= AliceResponseModel.TextMaxLenght && tts.Length + textTts.Length + ttsEnding.Length <= AliceResponseModel.TtsMaxLenght) { text.Append(textComment); tts.Append(textTts); } } tts.Append(ttsEnding); response = new SportsResponse(sportsRequest, text.ToString(), tts.ToString(), buttons); response.SessionState.NextNewsArticleId = nextNewsArticleId; response.SessionState.CurrentScene = SceneType; } else { var noResponseButtons = new List <AliceButtonModel>() { new SportsButtonModel(Sports_Resources.Command_LatestNews), new SportsButtonModel(Sports_Resources.Command_MainNews) }; response = new SportsResponse(sportsRequest, Sports_Resources.BestComments_NoComments, noResponseButtons); } response.SessionState.CurrentScene = SceneType; return(response); }
public override IAliceResponseBase Reply(SportsRequest sportsRequest) { SportKind sportKind = GetSportKind(sportsRequest); int pageIndex = GetPageIndex(sportsRequest); var newsResponse = GetNews(pageIndex, sportKind); int maxPageIndex = (int)Math.Ceiling(newsResponse.Total / (float)NewsPerPage) - 1; var buttons = new List <AliceButtonModel>(); if (pageIndex > 0) { buttons.Add(new SportsButtonModel("назад")); } if (pageIndex >= 0 && pageIndex < maxPageIndex) { buttons.Add(new SportsButtonModel("вперед")); } buttons.AddRange(Buttons); var news = newsResponse.Items; if (news.Any()) { var titles = news.Select(x => x.Title); string headerTts = GetSportKindText(HeaderTts, sportKind); string text = $"{headerTts}\n\n{string.Join("\n\n", titles)}"; string tts = $"{headerTts}{AliceHelper.SilenceString500}{string.Join(AliceHelper.SilenceString500, titles)}{AliceHelper.SilenceString1000}{Sports_Resources.Tips_Help}"; var response = new SportsGalleryResponse(sportsRequest, text, tts, buttons); response.Response.Card = new AliceGalleryCardModel { Items = new List <AliceGalleryCardItem>(), Header = new AliceGalleryCardHeaderModel(GetSportKindText(HeaderText, sportKind)) }; foreach (var newsArticle in news) { response.Response.Card.Items.Add(new AliceGalleryCardItem() { Title = AliceHelper .PrepareGalleryCardItemTitle(newsArticle.Title, GetTitleEnding(newsArticle), AliceHelper.DefaultReducedStringEnding), Button = new AliceImageCardButtonModel() { Url = newsArticle.Url } }); } response.Response.Buttons.AddRange(new List <AliceButtonModel>() { new AliceButtonModel("футбол"), new AliceButtonModel("хоккей"), new AliceButtonModel("баскетбол"), new AliceButtonModel("все") }); response.SessionState.PageIndex = pageIndex; response.SessionState.SportKind = sportKind; response.SessionState.CurrentScene = SceneType; return(response); } else { var response = new SportsResponse(sportsRequest, NoNewsText, buttons); response.SessionState.CurrentScene = SceneType; return(response); } }