Don't think Bender would dig the "non-sentient" classification.
Chatbots are all the rage nowadays, so I’ll show you how to plug one into your own Slack channel. It’s easy, fun, and, best of all, completely free!
Of course, you’ll need a Slack team which I’ll refer to as yourteam.slack.com throughout this post. The free plan includes up to 10 apps or service integrations and 5GB total file storage for the team which is more than enough for hooking up GitHub, your bot and your CI tool of choice. Semaphore, Travis, and Circle CI are all natively supported OOTB.
From there, you can create a custom integration for your bot:
Now, you’ve got an API token that allows your bot to connect to Slack! Copy this and keep it handy for the next step:
I used Norberto Lopes’ Slack API as the connector glue for my bot.
Pay particular attention how I get the bot to only react when it's called so it doesn’t get into any weird infinite loops (like an argument with itself).
Now for the fun part: writing your own custom commands so the bot can do some heavy lifting for you. As a simple prototype, I’ve asked it to fetch the 10-day forecast for my town via an
sw cmd trigger. Otherwise, it just repeats back what you said to it in the form of a question.
My next idea is to set a timer that will have it periodically go out and perform a task (i.e., check out how the Cubs are advancing in the Pennant Race). The possibilities are only limited by your imagination so let loose and get creative!
I use CircleCI (also free for building public repos) to build and deploy my bot as a Docker container to a DigitalOcean instance with every
git push. It’s much easier than it sounds and the entire process (building a new Golang binary hosted inside a container and deployed to CoreOS) takes less than three minutes!
Note where the code loads the Slack API token from the environment. I’ve set this up in my CircleCI build settings:
Because sometimes tokens have undigestible characters which can get strangely escaped, I’ve base64 encoded the original Slack API one and decode it at Docker runtime.
Let me know if you have any questions or suggestions!