https://github.com/erikboesen/bot-tutorial-python
An example GroupMe bot written in Python and hosted on Heroku.
https://github.com/erikboesen/bot-tutorial-python
Last synced: 3 months ago
JSON representation
An example GroupMe bot written in Python and hosted on Heroku.
- Host: GitHub
- URL: https://github.com/erikboesen/bot-tutorial-python
- Owner: ErikBoesen
- Created: 2019-09-14T22:52:30.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-26T22:27:51.000Z (almost 6 years ago)
- Last Synced: 2025-03-23T22:12:18.341Z (4 months ago)
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sample GroupMe Python Bot
**Python** | [**JavaScript**](https://github.com/groupme/bot-tutorial-nodejs)## Introduction
A simple GroupMe bot that reacts to messages sent within a group.
## Contents
* [Quickly get our sample bot up and running in your groups](#deploy)
* Deploy the code to heroku
* Create a bot
* Configure to your bot's credentials
* [Make changes to the bot](#pull)
* Pull the code down to your local machine
* Configure the local environment variables to your bot's credentials## Requirements:
* GroupMe account
* Heroku account
* [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli)## Deploy to Heroku:
Be sure to log in to Heroku, using your Heroku credentials, then click the link below.
[](https://heroku.com/deploy)
You should be taken to a page that looks like this:

Optionally, you can give your app a name, or instead leave it blank and let Heroku name it for you (you can change it later).

## Next, create a GroupMe Bot:
Go to:
https://dev.groupme.com/session/newUse your GroupMe credentials to log into the developer site.

Once you have successfully logged in, go to https://dev.groupme.com/bots/new

Fill out the form to create your new bot:
* Select the group where you want the bot to live
* Give your bot a name
* Paste in the URL of your newly deployed Heroku app
* `http://your-app-name-here.herokuapp.com/`
* (Optional) Give your bot an avatar by providing the URL of an image
* Click submit!Go here to view all of your bots:
https://dev.groupme.com/botsClick on the one you just created.

On your Bot's page, copy the Bot ID

## Add your Bot ID to your Heroku app:
Go here to see all of your Heroku apps and select the one you just created before:
https://dashboard-next.heroku.com/apps

On your app page, click settings in the top navigation:

On your app's setting page, find the Config Vars section and click the Reveal Config Vars button:

Then click edit:

Fill out the form to add an environment variable to your app:
* In the "key" field type: BOT_ID
* In the "value" field paste your Bot ID that you copied in the previous steps
* Click the save button
## Now go test your bot!
Go to GroupMe and type "/ping" in the group where your bot lives to see it in action.

## Pull the code to your local machine
Within terminal, change directory to the location where you would like the files to live, then run this command:
```sh
heroku git:clone -a YOUR_APP_NAME_HERE
```And then change directory into the new folder
```sh
cd YOUR_APP_NAME_HERE
```## Configure your local `BOT_ID` environment variable
You will need to set the `BOT_ID` environment variable so that your bot will know where to send its messages.
If you don't know what your Bot ID is, please refer back to [this](#get-bot-id) section, where it is explained how to retrieve it.
In your terminal, run
```sh
export BOT_ID=INSERT_YOUR_BOT_ID_HERE
```
You may wish to add this to a file that runs each time you start your shell, such as `~/.bashrc`.For Heroku, run:
```sh
heroku config:set BOT_ID=INSERT_YOUR_BOT_ID_HERE
```## Start the server
To test your bot locally, open terminal and install dependencies:
```sh
pip3 install -r requirements.txt
```Then start a local server.
```sh
FLASK_APP=bot.py flask run
```
or use gunicorn to imitate the production Heroku environment:
```sh
gunicorn bot:app
```Then navigate to `http://localhost:8000` in a browser.

## All done! Go play around and make the bot your own.