Example #1
0
        public async Task<string> Send(string message, string channel)
        {
            var payload = new SlackMessageData
            {
                Text = message
            };

            return await Send(payload, channel);
        }
Example #2
0
        public async Task<string> Send(SlackMessageData payload, string channel)
        {
            if (!channel.StartsWith("@") && !channel.StartsWith("#"))
                channel = "#" + channel;

            payload.UserName = _userName;
            payload.Icon_Emoji = _icon;
            payload.Channel = channel;

            var jsonContent = JsonConvert.SerializeObject(payload, Formatting.Indented,
                new JsonSerializerSettings { ContractResolver = new LowerCasePropertyNamesContractResolver() });

            HttpContent content = new StringContent(jsonContent, Encoding.UTF8, "application/json");

            var response = await _httpClient.PostAsync("", content);

            return jsonContent;
        }
Example #3
0
        private SlackMessageData GenerateSlackMessagePR(string repoURL, string owner, string repo, string requestedBy, List<dynamic> summary)
        {
            var payload = new SlackMessageData();
            payload.Text = string.Format("Responding to Request for PR status of <{0}/{1}/{2}|{1}/{2}> by @{3}\n\n\n", repoURL, owner, repo, requestedBy);

            if (summary.Count <= 0)
            {
                var attachment = new SlackAttachment
                {
                    Color = "good",
                    Pretext = "No PR statuses exist in repo"
                };
                payload.Attachments.Add(attachment);
            }

            foreach (var entry in summary)
            {
                var attachment = new SlackAttachment
                {
                    Color = entry.State.ToString().ToLower() == "success" ? "good" : "danger",
                    Pretext = string.Format("<{0}|Pull Request #{1}> - {2}\n\n", entry.URL, entry.Number, entry.State)
                };
                attachment.Text += String.Format("Pending: {0}\t", entry.Pending);
                attachment.Text += String.Format("Error:   {0}\t", entry.Error);
                attachment.Text += String.Format("Failure: {0}\t", entry.Failure);
                attachment.Text += String.Format("Success: {0}\n", entry.Success);

                payload.Attachments.Add(attachment);
            }

            return payload;
        }