diff --git a/SendSlackMessage/Entities/Attachment.cs b/SendSlackMessage/Entities/Attachment.cs new file mode 100644 index 0000000..ba8df0d --- /dev/null +++ b/SendSlackMessage/Entities/Attachment.cs @@ -0,0 +1,110 @@ +using SendSlackMessage.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace SendSlackMessage.Entities +{ + public class Attachment + { + [JsonPropertyName("fallback")] + public string Fallback { get; set; } + + [JsonPropertyName("text")] + public string Text { get; set; } + + [JsonPropertyName("pretext")] + public string Pretext { get; set; } + + [JsonPropertyName("fields")] + public List Fields { get; set; } = new List(); + /// + /// Can either be one of 'good', 'warning', 'danger', or any hex color code + /// + [JsonPropertyName("color")] + public string Color { get; set; } + + [JsonPropertyName("author_name")] + public string AuthorName { get; set; } + + [JsonPropertyName("author_link")] + public string AuthorLink { get; set; } + + [JsonPropertyName("author_icon")] + public string AuthorIcon { get; set; } + + [JsonPropertyName("title_link")] + public string TitleLink { get; set; } + + [JsonPropertyName("image_url")] + public string ImageUrl { get; set; } + + [JsonPropertyName("thumb_url")] + public string ThumbUrl { get; set; } + + [JsonPropertyName("footer")] + public string Footer { get; set; } + [JsonPropertyName("footer_icon")] + public string FooterIcon { get; set; } + + [JsonPropertyName("ts")] + public string FooterTimeStamp { get; set; } + + public Attachment() { } + public Attachment SetFooter(string footerText, string footerIcon/*, DateTime footerTimeStamp*/) + { + Footer = footerText; + FooterIcon = footerIcon; + //lack set FooterTimeStamp + return this; + } + + public Attachment AddField(string title, string value, bool _short = false) + { + Fields.Add(new Field + { + Title = title, + Value = value, + Short = _short + }); + + return this; + } + + public Attachment SetAuthor(string authorName, string authorLink = null, string authorIcon = null) + { + AuthorName = authorName; + AuthorLink = authorLink; + AuthorIcon = authorIcon; + return this; + } + + public Attachment SetColor(EnumColor color) + { + switch(color) + { + case EnumColor.Green: + Color = "good"; + break; + case EnumColor.Orange: + Color = "warning"; + break; + case EnumColor.Red: + Color = "danger"; + break; + default: + Color = null; + break; + } + return this; + } + public Attachment SetColor(string hexCodeColor) + { + Color = hexCodeColor; + return this; + } + } +} diff --git a/SendSlackMessage/Entities/Field.cs b/SendSlackMessage/Entities/Field.cs new file mode 100644 index 0000000..30637d3 --- /dev/null +++ b/SendSlackMessage/Entities/Field.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace SendSlackMessage.Entities +{ + public class Field + { + + [JsonPropertyName("title")] + public string Title { get; set; } + [JsonPropertyName("value")] + public string Value { get; set; } + [JsonPropertyName("short")] + public bool Short { get; set; } + } +} diff --git a/SendSlackMessage/Entities/Message.cs b/SendSlackMessage/Entities/Message.cs index f6b3f9c..7f951b9 100644 --- a/SendSlackMessage/Entities/Message.cs +++ b/SendSlackMessage/Entities/Message.cs @@ -29,6 +29,10 @@ public class Message [JsonPropertyName("response_type")] private string ResponseType { get => string.IsNullOrWhiteSpace(_responseType) ? "ephemeral" : _responseType; set => _responseType = value; } + + [JsonPropertyName("attachments")] + public List Attachments { get; set; } + public Message(string channel, string username, string iconEmoji, string iconUrl, string text, bool markdown = true) { Channel = channel; diff --git a/SendSlackMessage/Enums/EnumColor.cs b/SendSlackMessage/Enums/EnumColor.cs new file mode 100644 index 0000000..30b9a90 --- /dev/null +++ b/SendSlackMessage/Enums/EnumColor.cs @@ -0,0 +1,9 @@ +namespace SendSlackMessage.Enums +{ + public enum EnumColor + { + Red, + Orange, + Green + } +}