Easy Slack bot from Google Apps Script

Yusuke Hayashi
Mar 25, 2018 · 3 min read

This article explains how to create a slack bot which returns a gif url from giphy with Google Apps Script. (Easy and Free way to make a bot!)

STEP 1: Create Google App Script (GAS)

Image for post
Image for post
Create Google Apps Script from here.
Write this code.
Image for post
Image for post
Deploy as web app.
Image for post
Image for post
Change ‘Who has access to the app to “Anyone, even anonymous”’. Save the web app URL.

STEP 2: Get Giphy api key and Set it in GAS

Image for post
Image for post
From here, ‘Create an App’ and then enter the name and description whatever you want.
Image for post
Image for post
You can find the Giphy Api Key here!
Image for post
Image for post
Back to GAS and set the key to Script properties.
Image for post
Image for post
Currently you may have only ‘GIPHY_API_KEY’. You will get ‘SLACK_ACCESS_TOKEN’ next step.

STEP 3: Get Slack bot token add it to GAS property.

Image for post
Image for post
From here, click ‘Create New App’. Then enter the name and select which workplace to invite this bot to.
Image for post
Image for post
You can change basic information.
Image for post
Image for post
You need to add three features.
Image for post
Image for post
Image for post
Image for post
Add URL of GAS web apps of STEP 2. This checks if gas receive a post request and return a appropriate answer. (The code we wrote return it.)
Image for post
Image for post
Choose when to get post request. (Our bot needs it when someone send messages.)
Image for post
Image for post
Our bot needs to send message and unfurl the gif from link.
Image for post
Image for post
Install it to your workspace!
Image for post
Image for post
Then you can get the token from ‘OAuth & Permissions’. (Same page as that we added permissions.)
Image for post
Image for post
Yes, add it to GAS.
Image for post
Image for post
And change the code. Comment out the line 16 (This line is used only for the check).
Image for post
Image for post
And deploy as web app. we need the project version to be set ‘New’.

That’s All!

Image for post
Image for post
When you said the word ’dog’ in the channel which the Bot can hear it, it returns some gif!

If you want to know more about the code, please read this story.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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