slackhq/hubot-slack — pull request #107 by redhotvengeance (2014-12-10 00:02:04+00:00)
Title: Split up messages if longer than 4000 chars

This PR addresses and fixes #104.

Presently, if a message longer than 4000 chars / 16k bytes in size is sent, the [RTM API](https://api.slack.com/rtm) will reject the message and close the connection to Hubot. This is easily reproducible by calling `hubot help` once a sizable amount of scripts are added to the bot. Hubot will still be alive, but it stays disconnected from Slack and requires a restart before we can start talking to our robotic friend again.

This PR checks to see if a message is longer than 4000 chars before it is sent, and if it is longer than 4000 chars, it will split the message into chunks and send each one at a time. It will also attempt to split the message at the last occurring line break (within the 4000 char limit) to try to result in cleaner message chunks.