A Slack bot that relays information from HackGreenville Labs' Events API to Slack channels!
You can find the repository on Github.
To download this repo locally, clone it with git clone git@github.com:hackgvl/slack-events-bot.git
- Download the
docker-compose.yml
file to your desired hosting location and navigate to it - Run
docker-compose pull
to pull the latest version of the container and it's dependencies. - Modify
docker-compose.yml
by replacingBOT_TOKEN
andSIGNING_SECRET
values with values for a valid Slack App. - (Optional) By default, the app will create a sqlite database in the same
directory as
docker-compose.yml
. To modify the database location, modify thevolumes:
binding like below:
volumes:
- ./my-new-database-subdirectory/slack-events-bot.db:/usr/src/app/slack-events-bot.db
- Run
docker-compose pull
to pull the latest version of the container and it's dependencies. - Start the app by doing
docker-compose up
ordocker-compose up -d
to run in detached mode. Rundocker ps
to verify the status. - If desired, configure Docker to start automatically upon server reboot.
- To check the app's error log from within the Docker container, run
docker-compose logs -f
- Proxy a web server to the Docker container's port, as defined in the docker-composer.yml
willfarrell/autoheal (Docker Hub) is used
to provide autohealing capabilities that will automatically restart containers that repeatedly fail healthchecks. This service is not required for
local development, and as a result it is set to not run by default. If you would like to spin up this container for local testing purposes then please
specify the autohealing
profile whenever executing docker-compose up
:
docker-compose --profile autohealing up
The following needs to be included in an appropriate Apache .conf file, usually as part of an existing VirtualHost directive.
# Proxy requests to /events/slack to the 'Slack Bolt' Docker container port
ProxyPass /slack/events http://127.0.0.1:7331/slack/events
-
Clone the repo using the instructions above and enter the new directory.
-
Install the python version in
.tool-versions
. I recommend that you use asdf version manager, which will use the version in.tool-versions
.- To use asdf, first follow the install instructions.
- Then, install the python plugin with
asdf plugin-add python
- Then, run
asdf install
and possiblyasdf reshim
to install.
-
Load the environment variables specified in
.envrc.example
. I recommend you use direnv to keep this per-project.- To use direnv, follow the instruction examples.
- Then, create a slack app following the Slack Bolt tutorial.
- Copy
.envrc.example
to.envrc
, and fill in the private values from Slack into.envrc
. Make sure to never put these values into the code directly! - Run
direnv allow
to load the environment variables into your shell. This will need to be re-run if there are any changes to.envrc
.
-
Create a virtual environment with
python -m venv env
. -
Activate the venv with
source env/bin/activate
- Use
deactivate
to exit the venv if needed.
- Use
-
Install project dependencies using
pip install .
orpip install .[test]
to install development dependencies for testing -
Run the app with
python src/server.py
! -
Proxy a web server to the running app's port, as defined in the .envrc
PORT
value.
The following needs to be included in an appropriate Apache .conf file, usually as part of an existing VirtualHost directive.
# Proxy requests to /events/slack to the running 'Slack Bolt' app port
ProxyPass /slack/events http://127.0.0.1:3000/slack/events
- Clone the repo using the instructions above and enter the new directory.
- Modify
docker-compose.yml
by replacingimage: hackgvl/slack-events-bot
with the following:
build:
context: ./
- Modify
docker-compose.yml
by replacingBOT_TOKEN
andSIGNING_SECRET
values with values for a valid Slack App. - (Optional) By default, the app will create a sqlite database in the same
directory as
docker-compose.yml
. To modify the database location, modify thevolumes:
binding like below:
volumes:
- ./my-new-database-subdirectory/slack-events-bot.db:/usr/src/app/slack-events-bot.db
- Build and start the app with
docker-compose up --force-recreate --no-deps
- You can just start the app by doing
docker-compose up
ordocker-compose -d
to run in detached mode once it's been built
- You can just start the app by doing
This project uses some handy tools to assist with development. It's also recommended that you use a python virtual environment to help separate this project's dependencies from the rest of your system, and vice versa. Please feel free to give recommendations for any more tools if there are any that would be a good idea!
- direnv suggestions with
.envrc.example
for an easy way to set environment variables per-directory.- Once you have direnv installed, copy
.envrc.example
to.envrc
and replace with your slack dev application keys. Then, your slack application keys will only be available when you enter that directory!
- Once you have direnv installed, copy
- asdf version manager and
asdf-python with
.tool-versions
for an easy way to use the right python version per-directory. - black via
black src/
to format the source code in thesrc/
folder. - pylint via
pylint src/
to lint the source code in thesrc/
folder. We want this to stay at 10/10! - isort via
isort src/
to make sure that imports are in a standard order (black doesn't do this). - ssort via
ssort src/
to better group code. pip freeze
to figure out which versions of dependencies to use inpyproject.toml
. This is only necessary if you're adding or removing a new dependency to the project.
pip install .[test]
: Install test dependenciespython -m black src/
: Format source filespython -m isort --check src/
: sort imports with isortpython -m ssort --check src/
: sorts python codepython -m pylint src/
: Runs linter, try to get a 10/10 score!python -m pytest tests/
: Runs tests
This bot is licensed under the MIT license.
Thanks goes to these wonderful people (emoji key):
Olivia Sculley 🤔 💻 🐛 💬 📖 🚧 🚇 |
Jim Ciallella 🚇 🚧 📆 📖 |
Matthew Thornton 💻 🚇 |
Jake Anderson 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!