to tell Heroku that it should use this version of Python when compiling and running the code.

Hook up Version Control to Heroku

Next, we want to put our code under version control, a way to save each iteration of edits to our files (called a commit). To do this, we will commit our code to GitHub. You can make a GitHub account here and learn how to commit your code to GitHub here. For the purposes of this article, we will be working to deploy the Black Girl Magic bot. The code for it can be found via this link and you can use this guide to learn how to clone it.

Once you’ve cloned it, go to the Heroku deploy tab and connect your app to your GitHub repository so that Heroku will be able to pull and deploy your desired code. You will need to grant Heroku access to your Github account so that you can search all of your repositories. After connecting your account, search for your repository’s name and then click the “Connect” button to connect it to your Heroku app.

Once you’ve connected the repo to your app, you should see a screen like this:

Optional: If you want Heroku to automatically deploy updates to your bot when you make a commit to your GitHub repo, make sure to click the “Enable Automatic Deploys” button.

Now that we have connected our GitHub repository to your Heroku app, we need to deploy it.

Set Environment Variables in Heroku

If you are following this article using the Black Girl Magic bot, you will need to make sure to replace the ACCESS_TOKEN and VERIFY_TOKEN placeholders with actual codes. For information on how to access these codes, see the “Make your Bot on Facebook” section on my earlier blog post about bots. However, just leaving these tokens in your repo is bad practice and makes it easy for people to use your tokens for their own purposes. Thankfully, Heroku can help with this by allowing you to use config variables which allow you to securely keep the codes on Heroku and not in your code.

To do this, go to the “Settings” Tab section of your Heroku app and then click the “Reveal Config Vars.” You’ll need to enter a key/value pair for both the access and verify tokens and add them to make sure they are saved. Below is a good example of what this would look like:



Additionally, if you’re following the example code we’re using in this guide, you’ll need to modify lines 6 and 7 of the app.py file to find the tokens needed by getting them from the environment: