- Go to
https://api.slack.com/apps/ - Click the
Create New Appbutton - Choose
from scratch - Give it a name and pick a workplace, and click create
- Click
Socket modein the menu - Turn on
Connect using Socket Mode - Copy the Token (this is the
SLACK_APP_TOKEN). - Click
Event Subscriptions - Turn on
Enable Events - Open
Subscribe to bot events - Add the events
file_sharedmessage.channelsmessage.imapp_uninstalledtokens_revokedmember_left_channelmember_joined_channel - Click
OAuth & Permissionsin the menu - Go down to
Scopesand clickAdd an OAuth Scopeand add the scopes found in/application/backend/app/api/slack's GET/installmethod. - Go to
App Home - Go down to
Show Tabsand switch onMessages Tab(to allow DMs) - Go to
OAuth & PermissionsunderRedirect URLs - Add your install-redirect url which will be your domain (or localhost for development) +
/slack/callback - Add your login-redirect url which will be your domain (or localhost for development) +
/login/callback - Click
Slash Commandsin the menu - Click
Create new command - Fill in
/set-pizza-channelundercommand, fill inThis sets the current channel as the pizza channelunderShort Description - Click
save - Add another command
/pizzabot-admin-panelundercommand, fill inLink for administrating the pizzabotunderShort Description - Click
Basic Informationin the menu - Under App Credentials, copy
SLACK_CLIENT_ID,SLACK_CLIENT_SECRET,SLACK_SIGNING_SECRET - You now have
SLACK_APP_TOKEN,SLACK_CLIENT_ID,SLACK_CLIENT_SECRET,SLACK_SIGNING_SECRETwhich is needed in terraform or docker-compose
The frontend, backend, bot, message queue and database can all be run with docker compose by running docker-compose up. Optionally you can do docker-compose up -d [service] to only start one or more service. During development all services run behind an nginx instance to simplify their interactions. The ports are 80 and 443.
As we use Ouath2 for authentication we are forced to use https. Nginx needs valid ssl certificates, so you are gonna need to generate one with the command openssl req -x509 -nodes -newkey rsa:4096 -keyout nginx-selfsigned.key -out nginx-selfsigned.crt -sha256 -days 365 and add it to application/containers/development
NB: You'll need to supply the docker-compose file with slack credentials as mention in the Slack App Bot setup section. These are defined in a .env file in application/containers/development folder of the project. This file is not commited to the repository, so you have to create it manually. You can use the .env.example file as a template inside application/containers/development. You'll also need to supply cloudinary credentials if you want the uninstall handler to properly delete images, you should also update the upload_preset in handle_file_share in bot/src/slack/__init__.py to point to your own cloudinary account.
For flow of how the bot is added to a slack workspace, see digram in README/InstallFlow.png For flow of how login is handled with Slack, see diagram in README/LoginFlow.png
The legacy React app from PizzaBot.v2 is located in application/frontend. This is only used as a reference point for the new frontend with Next.js
Locales doesnt work properly in the alpine container used, meaning it's not a bug if stuff is localized wrong, such as the time string send in pizza event invites.
This repository is connected to Terraform Cloud where it is planned and then manually applied whenever a new tag is created.
Prod and staging live as separate workspaces in Terraform Cloud. The branch used in Terraform Cloud is main for the staging environment, and prod for the production environment. The prod branch is merged from main after the staging environment is tested. Terraform is not set up to automatically listen for changes on the branches (TODO), and a manual update of the target branch might be required to plan a new version.
When a planned version is applied, the changed environments are pushed to Heroku
We are using terraform to describe the infrastructure, which can be found in the /infrastructure folder. In addition to this the backend/bot have Procfile, runtime.txt, and .locales files that describe the process, heroku runtime and additional locales to include. While the frontend have .static in the public folder to indicate the application folder for the nginx buildpacker, and a .gitignore file to keep the files and folder in git.
- Go into the
infrastructurefolder and runterraform apply(not needed if using Terraform Cloud). - Go to the app settings of the frontend app in Heroku and under
Domainscopy theDNS Target. - Go to the app settings of the backend app in Heroku and under
Domainscopy theDNS Target. - Create a CNAME record with the hostname specified in the main terraform file for both the frontend and the backend and point them to the
DNS TARGETs from heroku. After a while routing and SSL should work flawlessly.
Infrastructure:
- prod/stag-backend: contains the database, papertrail instance, Rabbitmq instance, and backend application
- prod/stag-bot: contains an attachement to the database, an attachement to the papertrail instance, an attachement to the Rabbitmq instance, the bot worker
- prod/stag-frontend: contains source code of the Next.js-application, which is automatically detected and built by Heroku. The app is then automatically launched using by heroku with
npm run start, where the correct port is provided with the env-var$PORT.
NOTE Promoting apps from staging to prod has not been tested. We manually apply new prod and staging instances using Terraform.
The tests for this application were written using the pytest testing framework. The tests cover the blueprints, services, and broker handlers.
To run the backend tests, navigate to the backend directory of the project and run the following command:
python3 -m pytest tests
Optionally you can add the options -k [name of test suit or test function] (to only run certain tests), -s (to show print statements) and -v/-vv (to make tests more verbose).
TODO
Please follow these guidelines when contributing to this project:
- Fork the repository and create a new branch for your changes.
- Make changes or additions to the codebase or documentation.
- Write tests for any new functionality you add.
- Ensure that all tests pass.
- Update the documentation as necessary.
- Submit a pull request to the main repository.
We expect all contributors to adhere to our Code of Conduct. Please read it before contributing.
If you find any issues or have feature requests, please submit them on the issue tracker.
If you have any questions, please don't hesitate to reach out to us at https://www.blank.no/.
Thank you for your contributions!
By contributing to Pizza.v3, you agree that your contributions will be licensed under the GNU General Public License v3.0 license. Please see the LICENSE file for more information.
