Building a Serverless Acronym Bot on GCP using Cloud Functions

I was originally making this tutorial using DynamoDB, API Gateway and Lambda but I decided that I needed more practice with Google Cloud Platform.

Setup

The acronyms I’m using for this tutorial are from here.

  • Always Free, which provides limited access to many common GCP resources, free of charge.

Installing the bot

After signing into Slack, you’ll need to create a new app and give it a name and workspace. This is assuming you have the proper admin permissions and a slack workspace to do this.

Creating Function

After jumping over to Google Cloud Platform, you’ll need to navigate to Cloud Functions by clicking the navigation (top-left corner) and clicking Cloud Functions.

gcloud components update
  • data.json — where list of acronym dictionaries are stored
  • main.py — the file that contains the cloud functions logic
cd /tmp/
mkdir slackbot
cd slackbot
# source code here
# https://github.com/pyraven/gcp-serverless-slack-acronymbot/
vi config.json
# copy/paste the json from the github
# You'll need to edit this file and add the verification token from # earlier
vi data.json
# copy/paste as is from the github
vi main.oy
# copy/paste as is from the github
# create the cloud function
gcloud functions deploy acronym_bot --runtime python37 --trigger-http
httpsTrigger:
url: https://YOUR_REGION-YOUR_PROJECT_ID.cloudfunctions.net/acronym_bot

Testing

I created a new channel and invited the bot into the channel. Next I took a sec to… well you know…