Building a Slack Bot
Last Friday, in a @neoinnovate Slack channel, Principal, Michele Perras, encouraged us to build our own Slack bots. The thought of a Slack bot lingered over the weekend. I just spent ~3-days last week at the Code for America summit in Oakland, CA.
On Saturday morning, while having coffee, I decided to give the Slack API a try. I quickly found the slack-ruby-client .gem. Using the .gem, I was able to get to a working example pretty quickly - able to post a test message to a Slack channel from a Ruby prompt. Oh, the possibilities!
How about Slack + Code for America's API? I wrote a basic service using the Slack bot, as an exercise with CfA's API and the Heroku 1-click Deploy button.
The exploration resulted in civic-bot.
The bot supports a few commands so far, and it retrieves data from Code for America's open API. In this case, we enter a Slack command, like
dot cfa:issues, and that triggers a query to an external API based, and the result is displayed back in the Slack channel.
This proof-of-concept enables behavior-of-our-choosing based on specific string sequences in a Slack channel. The bot service is 1-click deployable to Heroku and runs as a worker. Just specify the Slack Bot's token when creating the service.
- Slack's API is extra-easy to use
- Programming bots is a challenging exercise in minimalist, functional design
Update: Code Snips
- Where message patterns are defined and responded to
- Where actions are defined
- Where implementation details are stuffed for now
Do you have any favorite Slack bots? Anything you'd love to see a Slack bot do? Share your thoughts below!