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

SlackMessagePostedListener stops working after some time #269

Open
berkayk opened this issue Sep 1, 2019 · 6 comments
Open

SlackMessagePostedListener stops working after some time #269

berkayk opened this issue Sep 1, 2019 · 6 comments

Comments

@berkayk
Copy link

berkayk commented Sep 1, 2019

Hi,

Thanks for this package. When I use messagePostedListener, after some time (like 2-3 hours later), this listener does not get executed. What could be the reason for that?

It is working fine when I first start the app.

SlackMessagePostedListener messagePostedListener = new SlackMessagePostedListener() {
            public void onEvent(SlackMessagePosted event, SlackSession session) {
                SlackChannel channelOnWhichMessageWasPosted = event.getChannel();
                String messageContent = event.getMessageContent();
                SlackUser messageSender = event.getSender();

                logger.warn("Received message on channel: " + channelOnWhichMessageWasPosted.getName() + " with sender: " + messageSender.getUserName());
}

session = SlackSessionFactory.createWebSocketSlackSession("************");
        try {
            session.connect();
        } catch (Exception e) {
            logger.error("Exception at connect. " + e.getMessage());
        }
        session.addMessagePostedListener(messagePostedListener);

Thanks.

@maragao
Copy link

maragao commented Dec 16, 2019

Same here.
Did you find a solution?

@octavioroncal
Copy link

This is related with the Goodbye Event that is not properly treated in this library. The library should reconnect when receive this event

@RankWeis
Copy link

RankWeis commented Mar 7, 2020

@octavioroncal Do you happen to know of any workaround? Is this an event we can catch ourselves in our code? Slack has seemingly increased the frequency of these goodbye events, and I'm now forced to restart my app every 12 hours in order to keep it running

@octavioroncal
Copy link

I've changed this library by https://github.com/seratch/jslack-maintenance-releases. This is a complete implementation of the Slack API and is currently maintained.

@fergonco
Copy link

fergonco commented Jun 12, 2020

Got the same problem and solved it (UPDATE: didn't work) building the session like this:

        slackSession = SlackSessionFactory.getSlackSessionBuilder(botKey)
                .withConnectionHeartbeat(20, TimeUnit.SECONDS)
                .withAutoreconnectOnDisconnection(true)
                .build();

and I am receiving goodbye events without being disconnected so far.

@fergonco
Copy link

Previous solution didn't work either, so I ended up creating a subclass of the session and intercepting the goodbye event in the onMessage method:

package com.ullink.slack.simpleslackapi.impl;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.ullink.slack.simpleslackapi.WebSocketContainerProvider;

public class HackedSlackSession extends SlackWebSocketSessionImpl {

    public HackedSlackSession(WebSocketContainerProvider webSocketContainerProvider, String authToken, boolean reconnectOnDisconnection, long heartbeat, TimeUnit unit) {
        super(webSocketContainerProvider, authToken, reconnectOnDisconnection, heartbeat, unit);
    }

    @Override
    public void onMessage(String message) {
        final JsonObject object = new JsonParser().parse(message).getAsJsonObject();
        if ("goodbye".equals(object.get("type").getAsString())) {
            // Here you reconnect, exit, ...
        }

        super.onMessage(message);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants