Event Driven Slack Bots — aka Serverless Slack Bots

Travis Reeder
Iron.io Technical Blog
3 min readApr 15, 2015

--

While I was writing a post for the Iron.io blog on how to write serverless slack bots, I got hooked on building bots. Ideas just keep popping into my head and I’ve been on a bot building rampage. I’ve got bots for everything from posting YouTube videos with /tubey (like /giphy for YouTube) to posting all our Salesforce Opportunity updates to our #sales channel to slackifying some of our devops.

In doing so, I’ve got the process nailed down to where I can write bots in just a few lines of code now (after making a new gem called slack_webhooks of course). And since I have them running on IronWorker, I don’t need to worry about where to run them or managing them (or paying for them). Just upload and forget.

Here’s the simplest example, hellobot:

hellobot.rb

When you type /hello in slack, hellobot responds with:

Once something becomes so easy to make, deploy and maintain, it’s hard not to make more. I’ve open sourced them all so you can use them too.

On to the Bots

Here’s some of them with screenshots of what they look like in Slack.

/tubey

Posts a random YouTube video based on the keyword you specify.

/roll

Rolls a die. Good for when you need to decide who’s going to go pick up the new round of Cappucino’s.

/vote

If you don’t run your company like a dictatorship, you need a good way to vote. This bot is for you.

opportunity_bot

opportunity_bot is probably the most useful bot of the bunch. It posts updates to any Opportunity in Salesforce to our #sales channel in Slack. This one works a bit different than the rest because it’s a scheduled bot, meaning it doesn’t run based on a slash command, but rather you schedule it to run every X minutes. IronWorker has scheduling built in so that makes scheduling a bot just as easy as the rest.

Can I use these with my Slack team?

Why of course you can. The source code for all of these along with step by step instructions for setting them up are here: https://github.com/treeder/slackbots

Enjoy.

--

--