Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nyc/c4q/ramonaharrison/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void main(String[] args) {
//myBot.sendMessage("Hello, world!");

// Post a pineapple photo to the #bots channel
myBot.sendMessageToBotsChannel("Testing name");
myBot.sendMessageToBotsChannel("I have a name and face now!");


}
Expand Down
20 changes: 20 additions & 0 deletions src/nyc/c4q/ramonaharrison/model/Attachment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.json.simple.JSONObject;

import java.util.ArrayList;

/**
* Created by Ramona Harrison
* on 8/26/16
Expand Down Expand Up @@ -29,9 +31,27 @@ public class Attachment {
// "footer"
// "footer_icon"
// "ts"
String fallback;
String color;
String pretext;
String author_name;

public Attachment(JSONObject json) {
// TODO: parse an attachment from the incoming json
if (json.get("fallback") != null) {
this.fallback = (String) json.get("fallback");
}
if (json.get("color") != null) {
this.color = (String) json.get("fallback");
}
if (json.get("pretext") != null) {
this.pretext = (String) json.get("fallback");
}
if (json.get("author_name") != null) {
this.author_name = (String) json.get("fallback");
}

//private List<Field> fields = new ArrayList<>();
}

// TODO add getters to access private fields
Expand Down
3 changes: 2 additions & 1 deletion src/nyc/c4q/ramonaharrison/network/Slack.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Slack {
private static final String ENDPOINT_DELETE_MESSAGE = "chat.delete";

public static final String BOTS_CHANNEL_ID = "C7KE0KTM4";
public static final String asUser="true";

/**
* Static method to test the Slack API.
Expand Down Expand Up @@ -82,7 +83,7 @@ public static SendMessageResponse sendMessage(String messageText) {
throw new RuntimeException(e);
}

URL sendMessageUrl = HTTPS.stringToURL(BASE_URL + ENDPOINT_POST_MESSAGE + "?token=" + API_KEY + "&channel=" + BOTS_CHANNEL_ID + "&text=" + messageText);
URL sendMessageUrl = HTTPS.stringToURL(BASE_URL + ENDPOINT_POST_MESSAGE + "?token=" + API_KEY + "&channel=" + BOTS_CHANNEL_ID + "&text=" + messageText + "&as_user=" + asUser);

return new SendMessageResponse(HTTPS.get(sendMessageUrl));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class SendMessageResponse extends Response {
public SendMessageResponse(JSONObject json) {
super(json);


if (json.get("channel") != null) {
this.channel = (String) json.get("channel");
}
Expand All @@ -32,6 +33,7 @@ public SendMessageResponse(JSONObject json) {
if (json.get("message") != null) {
this.message = new Message((JSONObject) json.get("message"));
}

}

public String getChannel() {
Expand Down