Building a Slack serverless bot with Google Apps Script and Spreadsheets

The Bot

  • help: shows the list of available commands
  • list: shows the list of available and busy servers
  • take <server_name> <reason>: marks the server as taken by you
  • leave <server_name>: marks the server as available
  • create <server_name>: adds a new server
  • remove <server_name>: removes an existing server
  • rename <old_server_name> <new_server_name>: renames a server

Alternative #1: Self-hosted bot. Nope

Alternative #2: A serverless bot? YES!

The Recipe

  • 1x Slack incoming webhook
  • 1x Slack outgoing webhook
  • 1x Google Spreadsheet
  • 1x Google Apps Script

Implementation

Spreadsheet

Blurry area corresponds to the ID of the spreadsheet that you should copy.

Set up Slack incoming webhook

Script

function doPost(e){
var commandReceived = e.parameter["text"];

if (commandReceived.match(/help/)) showHelp();
if (commandReceived.match(/list/)) listStaging();
if (commandReceived.match(/take/)) take(e);
if (commandReceived.match(/leave/)) leave(e);
if (commandReceived.match(/create/)) create(e);
if (commandReceived.match(/remove/)) remove(e);
if (commandReceived.match(/rename/)) rename(e);
}
  • SPREADSHEET_ID
  • SLACK_CHANNEL_NAME
  • SLACK_INCOMING_WEBHOOK

Set up Slack outgoing webhook

  • Channel: The channel we’ll send commands from.
  • Trigger Word(s): !staging
  • URL(s): The URL generated Google Apps Scripts in the last step.

Demo

Working example of Google Apps Script and Slack integration

--

--

--

Web developer who from time to time writes about Elixir, Javascript, Elm and other stuff

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Fuzzy string search

Starting out with MiniTest: how to write tests you’ll be proud of

Why I started taking tests seriously.

Change Password and Update Profile — Django Rest Framework

Being a Creator and a Coder: My 3 Month Post-Grad Update

Knative journey EP1: IBM cloud, your unique choice to have zero configuration for Knative with a…

CSS Grid Series — Responsive Website (Part 1)

Best-of-breed URL redirection services

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Victor Viruete

Victor Viruete

Web developer who from time to time writes about Elixir, Javascript, Elm and other stuff

More from Medium

How do we build the backend and connect it with the frontend

Uploading images to Cloudinary through the server using multer in a MERN stack web app

UI of image upload template for Cloudinary

Top 7 Modern PWA Framework: Pros and Cons

Term Paper 2022 Node js