Skip to content

Commit

Permalink
Add a Map in SlackAttachment to allow for fields not specified by dir…
Browse files Browse the repository at this point in the history
…ect fields.
  • Loading branch information
hcherndon committed Aug 8, 2015
1 parent 545e576 commit 38d0507
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/main/java/com/ullink/slack/simpleslackapi/SlackAttachment.java
Original file line number Diff line number Diff line change
@@ -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<SlackField> fields;
public Map<String, String> miscRootFields;

public List<String> markdown_in;
public List<SlackField> fields;

public List<String> markdown_in;

public SlackAttachment()
{
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

class SlackJSONAttachmentFormatter
{
Expand Down Expand Up @@ -45,6 +46,13 @@ public static List<JSONObject> encodeAttachments(SlackAttachment... attachments)
{
attachmentJSON.put("fallback", attachments[i].fallback);
}
if (attachments[i].miscRootFields != null)
{
for (Map.Entry<String, String> 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();
Expand Down

0 comments on commit 38d0507

Please sign in to comment.