Skip to content

Latest commit

 

History

History
175 lines (147 loc) · 10 KB

README.md

File metadata and controls

175 lines (147 loc) · 10 KB

slack-events-bot

All Contributors

A Slack bot that relays information from HackGreenville Labs' Events API to Slack channels!

Repository

You can find the repository on Github.

To download this repo locally, clone it with git clone [email protected]:hackgvl/slack-events-bot.git

Docker Instructions

  1. Download the docker-compose.yml file to your desired hosting location and navigate to it
  2. Run docker-compose pull to pull the latest version of the container and it's dependencies.
  3. Modify docker-compose.yml by replacing BOT_TOKEN and SIGNING_SECRET values with values for a valid Slack App.
  4. (Optional) By default, the app will create a sqlite database in the same directory as docker-compose.yml. To modify the database location, modify the volumes: binding like below:
    volumes:
      - ./my-new-database-subdirectory/slack-events-bot.db:/usr/src/app/slack-events-bot.db
  1. Run docker-compose pull to pull the latest version of the container and it's dependencies.
  2. Start the app by doing docker-compose up or docker-compose up -d to run in detached mode. Run docker ps to verify the status.
  3. If desired, configure Docker to start automatically upon server reboot.
  4. To check the app's error log from within the Docker container, run docker-compose logs -f
  5. Proxy a web server to the Docker container's port, as defined in the docker-composer.yml

Autohealing

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

Apache Example

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

Native (non-Docker) App Installation

  1. Clone the repo using the instructions above and enter the new directory.

  2. Install the python version in .tool-versions. I recommend that you use asdf version manager, which will use the version in .tool-versions.

    1. To use asdf, first follow the install instructions.
    2. Then, install the python plugin with asdf plugin-add python
    3. Then, run asdf install and possibly asdf reshim to install.
  3. Load the environment variables specified in .envrc.example. I recommend you use direnv to keep this per-project.

    1. To use direnv, follow the instruction examples.
    2. Then, create a slack app following the Slack Bolt tutorial.
    3. 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!
    4. 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.
  4. Create a virtual environment with python -m venv env.

  5. Activate the venv with source env/bin/activate

    1. Use deactivate to exit the venv if needed.
  6. Install project dependencies using pip install . or pip install .[test] to install development dependencies for testing

  7. Run the app with python src/server.py!

  8. Proxy a web server to the running app's port, as defined in the .envrc PORT value.

Apache Example

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

Docker Build Instructions

  1. Clone the repo using the instructions above and enter the new directory.
  2. Modify docker-compose.yml by replacing image: hackgvl/slack-events-bot with the following:
    build:
      context: ./
  1. Modify docker-compose.yml by replacing BOT_TOKEN and SIGNING_SECRET values with values for a valid Slack App.
  2. (Optional) By default, the app will create a sqlite database in the same directory as docker-compose.yml. To modify the database location, modify the volumes: binding like below:
    volumes:
      - ./my-new-database-subdirectory/slack-events-bot.db:/usr/src/app/slack-events-bot.db
  1. Build and start the app with docker-compose up --force-recreate --no-deps
    1. You can just start the app by doing docker-compose up or docker-compose -d to run in detached mode once it's been built

Development Tips

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!
  • 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 the src/ folder.
  • pylint via pylint src/ to lint the source code in the src/ 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 in pyproject.toml. This is only necessary if you're adding or removing a new dependency to the project.

License

This bot is licensed under the MIT license.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Olivia Sculley
Olivia Sculley

🤔 💻 🐛 💬 📖 🚧 🚇
Jim Ciallella
Jim Ciallella

🚇 🚧 📆 📖
Matthew Thornton
Matthew Thornton

💻 🚇 ⚠️
Jake Anderson
Jake Anderson

💻

This project follows the all-contributors specification. Contributions of any kind welcome!