Example #1
0
        public void Slack(string title, object message, SlackType type = SlackType.Info)
        {
            List <SlackDto.Attachment> attachmentList = new List <SlackDto.Attachment>();

            SlackDto.Attachment attachment = new SlackDto.Attachment();
            attachment.fields = new List <SlackDto.Field>();
            attachment.fields.Add(new SlackDto.Field {
                title = _setting.Title, value = ""
            });


            if (message.GetType().IsGenericType&& message.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(List <>)))
            {
                IList collection = (IList)message;

                for (int i = 0; i < collection.Count; i++)
                {
                    FillAttachment(collection[i], attachment);
                }
            }
            else
            {
                FillAttachment(message, attachment);
            }



            attachment.title      = title;
            attachment.title_link = _setting.TitleUrl;
            attachmentList.Add(attachment);
            string serializedContent = JsonConvert.SerializeObject(attachmentList.ToArray());

            _slackClient.SendMessage(serializedContent, type, true);
        }
Example #2
0
        public async void WriteMessage(string message, SlackType channel = SlackType.Info)
        {
            var postObject = new { channel = $"#{channel}", text = message };
            var json       = JsonConvert.SerializeObject(postObject);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            await _client.PostAsync(_url, content);
        }
Example #3
0
 public void Slack(object message, SlackType type = SlackType.Info)
 {
     try
     {
         string serializedMessage = JsonConvert.SerializeObject(message);
         _slackClient.SendMessage(serializedMessage, type);
     }
     catch
     {
     }
 }