/// <summary> /// Add Table. /// </summary> /// <param name="attachment">The <see cref="Attachment"/>.</param> /// <param name="table">The <see cref="Table"/>.</param> /// <returns>The <see cref="Attachment"/>.</returns> public static Attachment AddTable(this Attachment attachment, Table table) { if (attachment == null) { throw new ArgumentNullException(nameof(attachment)); } if (table == null) { throw new ArgumentNullException(nameof(table)); } table.Columns .ForEach(x => { var value = string.Empty; foreach (var row in x.Fields) { value += row.Title + "\n"; } value = value.TrimEnd('\n'); var header = new Field { Title = x.Name, Value = value, Short = true }; attachment .AddField(header); }); return(attachment); }
public void sendTopic(SlackMessageModel messageObj) { if (string.IsNullOrEmpty(messageObj.channel)) { messageObj.channel = this.slackChannel; } try { SbmClient mclient = new SbmClient(messageObj.channel); Message objMessage = new Message(messageObj.title); Attachment attachment = new Attachment() { Color = messageObj.color }; messageObj.attachments.ForEach(item => { attachment.AddField(item.itemTitle, item.itemValue, item.isShort); }); objMessage.AddAttachment(attachment); mclient.Send(objMessage); } catch (Exception e) { logger.Error(e.Message); logger.Trace(e.StackTrace); throw; } }