I knew my friend Matthew Turzo would be missed when he left Lyft. Mostly by me.

That's why I made an API to replicate his best, funniest and purest moments, and make him into a Slack bot.


(Turzobot is waiting for you to click...)


In Slack, from his bot, via the API...

Creating a bot of your friend with an API - TurzoBot
TurzoBot in action

So how do you do this? It's easy

  1. Make a doc of the things your friend says
  2. Make an API you can query to get random instances of what your friend says
  3. Make a Zapier integration into Slack to get those queries

Step 1: Create a Google doc of everything your friend says.

This is the easy, and fun part. Just go make a Google doc of everything your friend says.

Creating a friend with an API in Slackbot - Turzobot
A list of things that TurzoBot says

You'll notice three columns:

  1. The phrases
  2. The "Counter". These are all zero to start with.
  3. An index code. Make this whatever you like; it just has to be unique per line.

Actually, you don't have to use an index code. I'll get rid of it in a future version.

There are also two tabs.

  1. Tab 1: The list.
  2. Tab 2: The log. This is just an event log, to record what was sent out. You can use it for data collection later.

Step 2: Build an API using Google Scripts

This is the hard bit. But I've done it for you! See the source here on Github.

Why use an API? It's really nice to have an engine that can arbitrarily supply information to be used by any other interface.

Why use Google Apps Script (or GAS)? Well, it's a really nice way of deploying an API without a server and without a database. And it's free! Yes you're rate-limited, but you won't reach that limit unless your friend is super popular (or your API is unbelievably awesome).

If you want to know more about deploying web apps on Google Apps Script, look here.

Here is a brief explanation of the code.

  1. Listen for "GET" requests. It does this with the doGet() function, which is unique to GAS.
  2. Load the data in the Google Sheet into one array.
  3. Find the quotes that are least used (all of them, when you're just starting out; but later on, this will prevent your bot from seeming repetitive)
  4. Reduce the set of quotes to just the set of ones that haven't been seen in a while (lowest count number)
  5. Log the interaction
  6. Return the data it as a JSON object to whoever asked for it

Here's the full code:

I do some other stuff along the way, like

  • Log every interaction for debugging (in the second tab)
  • Return the total number of interactions done

When you deploy the app and make it publicly available, you test it by simply pasting the code into a browser. It should return something like:

{"botText":"Shut up, Dana. I didn't ask you","counter":96}

You can now use this data however you like!

Step 3: Build a Slack Bot via Zapier

In most companies, ordinary users can't just create bots using the Slack API interface.

But you CAN install Zapier, and you can deploy bots with Zapier.

One caveat: you can only deploy your bot to listen for

  • Any mention of the bot text (e.g. "@turzobot") in any public channel, or
  • Any mention of the bot text in one private channel

It's not perfect. You can't chat with the bot, for example, in case you're feeling lonely.

Creating a Slackbot using Zapier
Creating a Slackbot using Zapier

You set up the Zap to

  1. Listen for a message in the channel
  2. Filter it for the keyword you're looking for
  3. Fetch a random message from the API
  4. Respond with a message

The trickiest part to set up is the API call. You have to use Webhooks by Zapier. You might notice, however, that most fields are optional. The only one you really need is the one at the top - the URL. And for now, that's all you need!

Later, I plan on making my API more intelligent, replying with specific responses if keywords are used. But I haven't gotten there yet!