Importing a Python Slack bot from GitHub to Glitch
Need help with this tutorial? Join the Botmakers community!
Hey there, Stefan here, with a quick guide that will show you how to import an open source Slack bot as a new Glitch project and add it to your Slack group.
(I also wrote a similar guide that shows you how to import a node.js Twitter bot, so feel free to check that out as well.)
First, let’s go to the bot’s GitHub page. We are going to need to copy the part of the URL that has the author’s username and the name of the project, in this case
Now in Glitch, create a new project, then click the name of your project in the top left corner. This will bring up a menu.
Click the Advanced Options button at the bottom. Now you can click the Import from GitHub button that was revealed.
You can now paste the text you copied earlier into the popup prompt, in this case
Glitch officially only supports node.js, but it is possible to also run Python apps. I used this Python starter project to modify the imported project to get it to run.
The main change I had to do was to create a new file called
start.sh and add this:
#!/bin/sh python server.py
Next few steps will depend on the bot project you are importing (here is the Setup section for the meme bot project), but generally you will need to create a Slack app or set up an API token, add a slash command, or set up an incoming webhook.
Quick tip, to get your app’s URL, so that you can use it when setting up your Slack app, click the Show button next to your project’s name
Note that Glitch uses a
.env file to manage private data, like API keys, so you will have to save them into this file.
SLACK_API_TOKEN='abcd-1234-56789-1234567-89abcdefg' SLACK_WEBHOOK_URL='https://hooks.slack.com/services/ABCDE/FGH1234/56789abcdefg' SLACK_SLASH_COMMAND_TOKEN='abcd1234efghij'
This is actually enough for this particular project, because the values are being read directly from the environment, but in most cases you will have to update the actual project code. Here’s how you use environmental variables with Python:
import os print os.environ['SLACK_API_TOKEN']
If you’re importing a node.js-based bot, you can access your variables like this:
And finally, here’s the imported project on Glitch.
Thanks for following along! If you have any questions, be sure to stop by the Botmakers community, or you can just join to play with our meme bot 🙂