Skip to content

Commit

Permalink
Separated out websocket connection method (#99)
Browse files Browse the repository at this point in the history
Now you can restart the websocket connection by just calling the `startWebSocketConnection()` method from your bot.
  • Loading branch information
tdl-jturner authored and rampatra committed Jun 10, 2018
1 parent 389f5df commit 290ef9a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions jbot/src/main/java/me/ramswaroop/jbot/core/slack/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public final void reply(WebSocketSession session, Event event, Message reply) {
logger.error("Error sending event: {}. Exception: {}", event.getText(), e.getMessage());
}
}

public final void reply(WebSocketSession session, Event event, String text) {
reply(session, event, new Message(text));
}
Expand Down Expand Up @@ -283,8 +283,15 @@ private BotWebSocketHandler handler() {
* and after which your bot becomes live.
*/
@PostConstruct
private void startWebSocketConnection() {
private void startRTMAndWebSocketConnection() {
slackService.startRTM(getSlackToken());
startWebSocketConnection();
}

/**
* Starts websocket connection using the existing slackService.
*/
public void startWebSocketConnection() {
if (slackService.getWebSocketUrl() != null) {
WebSocketConnectionManager manager = new WebSocketConnectionManager(client(), handler(), slackService.getWebSocketUrl());
manager.start();
Expand Down

0 comments on commit 290ef9a

Please sign in to comment.