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

Bot goes offline automatically #24

Closed
thirunar opened this issue Nov 22, 2016 · 4 comments
Closed

Bot goes offline automatically #24

thirunar opened this issue Nov 22, 2016 · 4 comments

Comments

@thirunar
Copy link

Hi,

Thanks for the awesome framework. I'm using your framework to create a Slack Bot. I have an issue when the bot tries to reply back with large text (around 10k characters). The bot simply goes offline without any error. I tried debugging the issue, but couldn't get into a solution.

I suspect, the web socket session is getting closed for larger text. I tried setting the text limit for the session, even that didn't work.

Can you help me fix the issue?

TIA!

@rampatra
Copy link
Owner

rampatra commented Nov 24, 2016

Can you please send me the logs. I don't think larger text would be the issue, it rather seems to be an exception in your code. I too faced such issue but later I figured out that there was an exception in my bot (the bot which I made using jbot and not jbot itself) code.

@thirunar
Copy link
Author

thirunar commented Nov 24, 2016

The problem, there was no exception when the bot goes offiline. I'm attaching the code, let me know, if this helps

    @Controller(events = {EventType.DIRECT_MENTION, EventType.DIRECT_MESSAGE})
    public void onReceiveDM(WebSocketSession session, Event event) {
        LOGGER.info("Received: {}", event.getText());

        String response = formatCode(requestProcessor.processRequest(event.getText()));
        reply(session, event, new Message(response));
        stopConversation(event);
    }

RequestProcessor.processRequest

    public String processRequest(String request) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = createHeaders("admin", "xyz");
        String url = getUrl(request);
        if (url != null) {
            if (request.contains("livenodes")) {
                HttpEntity entity = new HttpEntity(headers);
                ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
                return response.getBody();
            } else {
                headers.setAccept(asList(MediaType.APPLICATION_XML));
                HttpEntity entity = new HttpEntity(headers);
                try {
                    ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
                    return PrettyPrinter.formatXML(response.getBody());
                } catch (Exception e) {
                    return "Sorry!! Error processing the request!!!";
                }
            }
        }
        return "";

    }

And also, it would be helpful, if you can share what exception you faced in your bot

@ldavison
Copy link

ldavison commented Dec 2, 2016

See the limits section for RTM. It specifically says:

The message server will disconnect any client that sends a message longer than 16 kilobytes. This includes all parts of the message, including JSON syntax, not just the message text.

@thirunar
Copy link
Author

thirunar commented Dec 6, 2016

Thanks a lot!! This helps. I split the message into small chunks.

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

3 participants