Skip to content

Commit

Permalink
Merge pull request #21 from hcherndon/master
Browse files Browse the repository at this point in the history
Add a Map in SlackAttachment to allow for fields not specified by dir…
  • Loading branch information
bcorne committed Aug 8, 2015
2 parents 545e576 + 38d0507 commit 6f0c94e
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

1 comment on commit 6f0c94e

@hcherndon
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you very much! :)

Please sign in to comment.