/message_api

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

message-api

message-api is an api for collecting messages from an audience.

The central idea is to provide an api that is not dependent on registration on website or the installation of an app. Messages can be posted using dynamic qr-codes containing a link to the message submission form including a secret. Once a qr-code is used, a new one will be generated.

The endpoint to generate a qr code requires authentication. Hence the api can be used at an event for participants to post messages, everything can be available online but only physically present people can post messages using the qr codes that are displayed at the event. Everyone can read the messages posted.

There are rudimentary frontends for the message api built in dash. The messages_frontend displays all posted messages and the qr_frontend displays the qr-codes containing the secrets for posting messages. There is an example on how the form can be embedded into a wordpress homepage.

getting started

Install python >=3.10, poetry and docker-compose.

Run

poetry install

to install dependencies.

Change into the virtual environment

poetry shell

Setup the .env-file by copying the .env.example to .env

cp .env.example .env

and filling the JWT_SECRET_KEY and ADMIN_PASSWORD.

Choose a password for the admin account and generated the hashed admin password by exectuting

make generate-admin-pw

A JWT_SECRET_KEY can be generated by executing

openssl rand -hex 32

run api (without frontends, suitable for development and adjustments)

Now we are ready to go!

Run

make docker-redis

to start redis. This holds the messages and tokens.

Run

make run-api

to start the api.

The swagger-ui / redoc describes the under localhost:8000/docs respectively localhost:8000/redoc.

run api, frontends and redis with docker-compose

Run

make build-base-image
make build-images

to build the base image with dependencies and build the message api and the 2 frontend services.

Run

make docker-run

to start the api, frontends and redis.

The qr frontend is served under localhost:8050, the messages-frontend under localhost:8051 and the api under localhost:8000.

Remark: The docker-compose definition does not include an access token for redis. The api will read the environment variable ACCESS_TOKEN (or ACCESS_TOKEN directly from .env).

Deployment

A rudimentary nginx configuration is available under etc/nginx for deploying the docker-compose docker/message-api.yaml.