Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issues #38 and #126 #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion jbot/src/main/java/me/ramswaroop/jbot/core/slack/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.regex.Matcher;

/**
Expand All @@ -43,6 +44,17 @@ public abstract class Bot extends BaseBot {
private static final Logger logger = LoggerFactory.getLogger(Bot.class);

private final Object sendMessageLock = new Object();
private Function<String,String> messageEncoder = s ->
s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");

/**
* Encoder of messageText.
* To avoid encoding the identity-function can be applied: Function.identity()
* @param messageEncoder
*/
public void setMessageEncoder(Function<String, String> messageEncoder) {
this.messageEncoder = messageEncoder;
}

/**
* Service to access Slack APIs.
Expand Down Expand Up @@ -288,7 +300,7 @@ private void invokeChainedMethod(WebSocketSession session, Event event) {
* @return encoded message
*/
private String encode(String message) {
return message == null ? null : message.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
return message == null ? null : messageEncoder.apply(message);
}

private StandardWebSocketClient client() {
Expand Down