Skip to content

Commit

Permalink
Set message type in reply method only when it is not explicitly set b…
Browse files Browse the repository at this point in the history
…y the user and add support for markdown in attachment model (#50)

* Set message type in reply method only when it is not explicitly set by the user.
* Optimized imports
* Added attribute for markdown support in attachments
* Added inclusion of null attributes
  • Loading branch information
abstract-karshit authored and ramswaroop committed Jun 14, 2017
1 parent b27fc96 commit f61a160
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
21 changes: 16 additions & 5 deletions jbot/src/main/java/me/ramswaroop/jbot/core/slack/Bot.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package me.ramswaroop.jbot.core.slack;

import com.fasterxml.jackson.databind.ObjectMapper;
import me.ramswaroop.jbot.core.slack.models.Event;
import me.ramswaroop.jbot.core.slack.models.Message;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -14,13 +13,23 @@
import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.PostConstruct;

import me.ramswaroop.jbot.core.slack.models.Event;
import me.ramswaroop.jbot.core.slack.models.Message;

/**
* Base class for making Slack Bots. Any class extending
* this will get all powers of a Slack Bot.
Expand Down Expand Up @@ -234,7 +243,9 @@ public boolean isConversationOn(Event event) {
*/
public final void reply(WebSocketSession session, Event event, Message reply) {
try {
reply.setType(EventType.MESSAGE.name().toLowerCase());
if (StringUtils.isEmpty(reply.getType())) {
reply.setType(EventType.MESSAGE.name().toLowerCase());
}
reply.setText(encode(reply.getText()));
if (reply.getChannel() == null && event.getChannelId() != null) {
reply.setChannel(event.getChannelId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

/**
* Created by ramswaroop on 12/06/2016.
*/
Expand Down Expand Up @@ -31,6 +33,9 @@ public class Attachment {
private String footerIcon;
private String ts;

@JsonProperty("mrkdwn_in")
private List<String> markdownIn;

public String getFallback() {
return fallback;
}
Expand Down Expand Up @@ -150,5 +155,13 @@ public String getTs() {
public void setTs(String ts) {
this.ts = ts;
}

public List<String> getMarkdownIn() {
return markdownIn;
}

public void setMarkdownIn(List<String> markdownIn) {
this.markdownIn = markdownIn;
}
}

0 comments on commit f61a160

Please sign in to comment.