public void Emit(LogEvent logEvent) { try { _client.IncomingWebHook(_formatter.CreateMessage(new[] { logEvent })).GetAwaiter().GetResult(); } catch (Exception ex) { SelfLog.WriteLine("Exception while emitting message from {0}: {1}", this, ex); } }
protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events) { await _client.IncomingWebHook(_formatter.CreateMessage(events)); }
/// <summary> /// Posts attachments. /// </summary> public static Task PostAttachments(this ISlackClient slackClient, IEnumerable <Attachment> attachments, CancellationToken ctx = default(CancellationToken)) { return(slackClient.IncomingWebHook(new IncomingWebHookRequest { Attachments = attachments }, ctx)); }
/// <summary> /// Posts markdown-formatted text. /// </summary> public static Task PostMarkdown(this ISlackClient slackClient, string markdown, CancellationToken ctx = default(CancellationToken)) { return(slackClient.IncomingWebHook(new IncomingWebHookRequest { Text = markdown, Markdown = true }, ctx)); }
/// <summary> /// Posts text content, without formatting. /// </summary> public static Task PostText(this ISlackClient slackClient, string text, CancellationToken ctx = default(CancellationToken)) { return(slackClient.IncomingWebHook(new IncomingWebHookRequest { Text = text, Markdown = false }, ctx)); }
public async Task GatherReviews(string product, uint appId, CancellationToken token) { logger.LogInformation("Gathering reviews for app {0}", appId); GetReviewsResponse response = await steam.GetReviews(new GetReviewsRequest(appId) { Filter = ReviewFilter.Recent }, token); logger.LogInformation("Got {0} recent reviews", response.Reviews.Count); IDictionary <uint, Review> reviews = response.Reviews.ToDictionary(x => x.RecommendationId, x => x); uint[] recentReviewIds = reviews.Keys.ToArray(); uint[] seenReviewIds = (await seenItemRepository.GetSeenItems(recentReviewIds.Select(x => x.ToString()).ToArray(), token)).Select(x => uint.Parse(x)).ToArray(); uint[] unseenReviewIds = recentReviewIds.Except(seenReviewIds).ToArray(); logger.LogInformation("Of which {0} are unseen", unseenReviewIds.Length); Review[] unseenReviews = reviews.Where(x => unseenReviewIds.Contains(x.Key)) .Select(x => x.Value) .OrderBy(x => x.Created) .ToArray(); foreach (Review unseenReview in unseenReviews) { var reviewContent = unseenReview.Comment.Truncate(512); string reviewUrl = $"https://steamcommunity.com/profiles/{unseenReview.Author.SteamId}/recommended/{appId}"; logger.LogInformation("Posting review {0} to Slack", reviewUrl); TranslationResult translationResponse = null; try { translationResponse = await translation.TranslateTextAsync(reviewContent, "en", null, null, token); } catch (GoogleApiException e) { logger.LogError(e, "Encountered error translating review."); } var reviewFlags = new List <string> { unseenReview.SteamPurchase ? "Steam Activation" : "Key Activation", unseenReview.WrittenDuringEarlyAccess ? "Early Access" : "Released" }; if (unseenReview.ReceivedForFree) { reviewFlags.Add("Received for Free"); } var fields = new List <Field> { new Field { Title = $"Original Text ({translationResponse?.DetectedSourceLanguage ?? "unknown"})", Value = reviewContent, Short = false }, new Field { Title = "Play Time Total", Value = unseenReview.Author.PlayTimeForever.Humanize(), Short = true }, new Field { Title = "Play Time Last 2 Weeks", Value = unseenReview.Author.PlayTimeLastTwoWeeks.Humanize(), Short = true }, new Field { Title = "Games Owned", Value = unseenReview.Author.NumGamesOwned.ToString("N"), Short = true }, new Field { Title = "Type", Value = string.Join(", ", reviewFlags) } }; if (translationResponse != null && translationResponse.DetectedSourceLanguage != "en") { fields.Insert(1, new Field { Title = $"Auto-Translated Text", Value = translationResponse.TranslatedText, Short = false }); } await slack.IncomingWebHook(new IncomingWebHookRequest { Username = $"{product}", Attachments = new List <Attachment> { new Attachment { AuthorIcon = "https://steamcommunity-a.akamaihd.net/public/shared/images/userreviews/" + (unseenReview.VotedUp ? "icon_thumbsUp.png" : "icon_thumbsDown.png"), AuthorName = (unseenReview.VotedUp ? "Recommended" : "Not Recommended") + " (open review)", AuthorLink = reviewUrl, Fields = fields } } }, token); logger.LogInformation("Inserting review {0} into DynamoDB", unseenReview.RecommendationId); await seenItemRepository.SetItemSeen(unseenReview.RecommendationId.ToString(), token); } logger.LogInformation("Finished posting reviews."); }