Serverless Slack Integrations

Jed Wood
3 min readDec 3, 2014

--

Create simple apps that ping and poll your Slack channels with nothing more than Google’s built-in services.

For some background, check out how I create simple apps and prototypes with Google Sheets and Google Apps Script. The example I’ll deconstruct in this post is one that reports stats on a Slack channel.

Slack Stats

The UX team at Ancestry has a #critique channel where everybody posts design comps and gets feedback. We started using this right about the time our team got too big for the weekly “everybody show us what you’re working on” meetings. It’s been really valuable to our multi-office team.

Our director wanted a simple, light-hearted way of cajoling the team to post frequently and chiding those who haven’t been participating. I built a little bot that posts to the channel at the end of each week and month. You get top kudos if you’ve posted designs, a satisfactory mention if you’ve commented, and something passive-aggressive if you’ve been silent.

slack stats in action

Just a Script

Many of my “serverless” apps use a Google Spreadsheet as a database. For Slack Stats we don’t need to store any data, so it uses a standalone script file without a spreadsheet. To speed up the creation of other Slack-related apps, I created a Slack library script that handles the underlying details of making call to the well-documented Slack API. Now I can include that library in any project and fetch messages with this simple line:

var msgs = Slack.getMessages(channel, oldest, latest)

Timed Triggers

The Google interface for setting up cron-like triggers is pretty straightforward. I’ve created one to run at the end of each week and month.

Google Apps Script triggers

Those “reportToSlack” functions use my Slack library to call the Slack API, fetch the message, format our fun little message, and then post to the #critique channel. There are a few different ways Slack let’s you set up integrations, but one simple option is an “incoming Webhook.”

On Demand

Update May 2015 — it seems that Slack has changes something so that it no longer automatically follows redirects, which means slash commands as described below won’t work right.

If all we use are timed triggers, we don’t need to “deploy” our Google script as an HTTP-accessible endpoint. We’ll need to do that if we want to interact with out app from outside of Googleland. Doing so is pretty straightforward. You’ll want to select the “anyone, even anonymous” option when deciding who has access, since the Slack API doesn’t have Google credentials. ☺

When you deploy, you’ll get a unique HTTP endpoint. Now jump over to Slack and create a custom slash command, paste the Google endpoint into the form and configure the other options. For Slack Stats, I’ve set things up to allow a ‘days’ parameter. That allows anybody to type:

/stats 10

into Slack and get a look at the past 10 (or 3 or 90) days.

Well, that’s Slack Stats. Anybody I share the script with on my team (through the normal Google Docs sharing process) can edit the messages and tweak the parameters. As easy as Git, Heroku, npm, and other modern dev tools make code collaboration and app deployment, nothing is quite as simple as this, especially when collaborating with teammates that aren’t yet familiar with the modern dev workflows and toolchains.

--

--