A Flask Slack bot API to interface with CSH Quotefault.
Computer Science House (CSH) has a weekly newsletter named Segfault, which is commonly distributed with an out of context quote from some member. Historically, these quotes were submitted by email, but since the email aliases is generally given to a different member every year, there is no central, accessible repository for quotes. Because of this, many wonderful quotes are unrecoverable. To mitigate this problem, an annual CSH hackathon, Nicholas Mercadante created Quotefault, a service for submitting, storing, and viewing quotes. Quotefault has since become quite prevalent, and so during another hackathon, Skyler Clark and Devin Matté created the Quotefault API to allow more projects to build off of quotefault.
This bot is built in Python Flask. It handles a POST request from Slack, interprets the quote request, and responds with a quote in channel, or an ephemeral help message if the command isn't understood. It uses the Quotefault API to interact with the Quotefault database.
This project provided an opportunity to play with Python Flask and the Slack API, and Quotefault had previously been floated as a possible slack integration. I wanted a project for the summer, so I
Contributors welcome! Make a PR, and it will be checked with Travis and Pylint. You'll need to make it pass Pylint before it can be merged.
- Make sure you have python3 installed (Here's a guide)
- You'll need pip (pip3), the python package manager (Here's that guide)
- Run these commands to setup virtualenv and install the project dependencies to that virtualenv. This way you can have specific versions for each project without installing everything to your system.
python3 -m virtualenv venv # Sets up virtualenve in the venv directory in your working directory
source venv/bin/activate # Activates the virtual environment
pip install -r requirements.txt # Installs all of the dependencies listed in the requirements to the virtualenv
- Set up your configuration file:
- Copy
config.env.py
toconfig.py
- Set
SERVER_NAME = 127.0.0.1:5000
, which is where flask will serve to. This needs to be set or else flask gets upset. You can fill in other fields if you get an api key or you're running a local mySQL DB, but they aren't strictly necessary if you aren't going to manually emulate Slack sending slash commands. - Set debug mode:
export FLASK_ENV=development
- If flask doesn't find app.py, run
export FLASK_APP=app.py
- Run with
flask run
- Make your changes, make sure it runs, and make a pull request. If you need some help with that, either checkout GitHub's guide or ping me on Slack or something.
- Make sure your PR passes pylint, and I should merge it or message you (or comment) about any comments I have. If I don't, poke me on Slack.
If you want to check style before making a PR, you can run pylint csh_quotefault_bot
(or pylint -f colorized csh_quotefault_bot
for the prettier version).