diff --git a/src/main/java/com/ullink/slack/simpleslackapi/SlackAttachment.java b/src/main/java/com/ullink/slack/simpleslackapi/SlackAttachment.java index b6889998..6cc000c7 100644 --- a/src/main/java/com/ullink/slack/simpleslackapi/SlackAttachment.java +++ b/src/main/java/com/ullink/slack/simpleslackapi/SlackAttachment.java @@ -1,22 +1,26 @@ package com.ullink.slack.simpleslackapi; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class SlackAttachment { - public String title; - public String titleLink; - public String fallback; - public String text; - public String pretext; - public String thumb_url; + public String title; + public String titleLink; + public String fallback; + public String text; + public String pretext; + public String thumb_url; - public String color; + public String color; - public List fields; + public Map miscRootFields; - public List markdown_in; + public List fields; + + public List markdown_in; public SlackAttachment() { @@ -54,6 +58,15 @@ public void addMarkdownIn(String value) markdown_in.add(value); } + public void addMiscField(String key, String value) + { + if (miscRootFields == null) + { + miscRootFields = new HashMap<>(); + } + miscRootFields.put(key, value); + } + public void setTitle(String title) { this.title = title; diff --git a/src/main/java/com/ullink/slack/simpleslackapi/impl/SlackJSONAttachmentFormatter.java b/src/main/java/com/ullink/slack/simpleslackapi/impl/SlackJSONAttachmentFormatter.java index d5708d72..aa6b1700 100644 --- a/src/main/java/com/ullink/slack/simpleslackapi/impl/SlackJSONAttachmentFormatter.java +++ b/src/main/java/com/ullink/slack/simpleslackapi/impl/SlackJSONAttachmentFormatter.java @@ -7,6 +7,7 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; +import java.util.Map; class SlackJSONAttachmentFormatter { @@ -45,6 +46,13 @@ public static List encodeAttachments(SlackAttachment... attachments) { attachmentJSON.put("fallback", attachments[i].fallback); } + if (attachments[i].miscRootFields != null) + { + for (Map.Entry entry : attachments[i].miscRootFields.entrySet()) + { + attachmentJSON.put(entry.getKey(), entry.getValue()); + } + } if (attachments[i].markdown_in != null && !attachments[i].markdown_in.isEmpty()) { JSONArray array = new JSONArray();