VMSh Tasks Bot is an asynchronous Telegram assistant used by the Moscow math circle to manage problem assignments, collect solutions, and broadcast live game updates. The project combines an aiogram 3 bot, aiohttp web applications, a SQLite database, and Google Sheets synchronization routines so tutors can administer tasks from a single workflow.
- The
main.pyentry point wires every application, exposes the aiohttp server on port 8179 during development, and keeps graceful shutdown routines for background tasks. apps/contains pluggable aiohttp modules: the Telegram bot, a teachers' scoreboard (results_app.py), the cooperative game dashboard (game_web_app.py), and an optional Zoom webhook parser (zoom_events_parser.py). The list of enabled modules is driven by theappssetting from the runtime configuration.- Database access lives in
db_methods/, which bootstraps SQLite via yoyo migrations and offers domain-specific helpers for lessons, queues, and game state. - Google Sheets remain the single source of truth for problems, students, and teachers;
models/spreadsheets.pyloads sheets into SQLite when the database is empty.
- Telegram command handling, custom keyboards, and rate limiting implemented on top of aiogram 3.
- Teacher-only dashboards for results and statistics delivered through aiohttp routes that authenticate via web tokens stored in SQLite.
- Cooperative "game" web interface with websocket updates backed by NATS and Telegram notifications when treasure chests are opened.
- Zoom webhook ingestion that populates the queue table and normalizes participant names to match internal records.
A deeper breakdown of components, data flow, and external dependencies is available in ARCHITECTURE.md.
- Python 3.13+ and SQLite 3.35+ (matching the deployment prerequisites used in production).
- Access to Telegram Bot API credentials, Google Sheets service account JSON, and spreadsheets that mirror the schemas consumed by
models/spreadsheets.py. - (Optional) A running NATS server when enabling realtime game dashboards or other cross-process messaging.
- Copy
creds_test/vmsh_bot_config_test.json_exto eithercreds_test/vmsh_bot_config_test.jsonor the production counterpart undercreds_prod/, then fill every field with the real bot token, Google Sheets key, webhook host, database path, and messaging channel identifiers. - Place the Google service account JSON obtained from Google Cloud under
creds_test/vmsh_bot_sheets_creds_test.json(or the production path) so thathelpers.configcan read it on startup. - The configuration loader automatically runs yoyo migrations and resolves the SQLite path before returning a
Configdataclass instance to the rest of the codebase. - The only environment flag is
PROD. SetPROD=trueto switch into production mode, otherwise omit it (or set any other value) to load the development credentials.
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt # optional, only needed for pytest and HTTP fixtures- Ensure SQLite and (optionally) NATS are available. Any missing migrations are applied automatically the first time
helpers.configis imported. - Start the Telegram bot and aiohttp server in polling mode:
The aiohttp server listens on http://127.0.0.1:8179 and prints the list of registered routes for enabled apps.
source .venv/bin/activate python main.py - When realtime features are required, start a NATS server (for example
nats-server -DVordocker run --rm -p 4222:4222 nats:latest) before launching the bot so websocket broadcasts succeed.
- Enable
PROD=true, provide the production JSON credentials undercreds_prod/, and run the project behind gunicorn so that aiohttp handles Telegram webhooks instead of polling viaapps.tg_bot.setup_tgbot_webhook. - Deployment automation, nginx examples, and SSL prerequisites are documented (in Russian) under docs/deploy.md.
Run the complete suite with either the helper script or pytest directly:
./run_tests.sh
# or
pytest -vvs tests/The tests rely on the same configuration loader and will create temporary databases using the paths from your JSON configuration files.
An OpenAPI specification that describes the exposed aiohttp routes (login forms, teacher dashboards, game actions, and Zoom hooks) is maintained in openapi.yaml.
docs/for_teacher.md,docs/for_admin.md, anddocs/settings.mdprovide end-user manuals for the Telegram bot (currently in Russian).docs/tests.mddocuments historical testing tips; follow this README for the latest dependency names.
The git history is dominated by Sergey Shashkov, with additional contributions from eyakm1, chvtl, dirigabel, Max Ushakov, Oleg Yunin, ChV, and Viktor.
The project is distributed under the MIT License; see LICENCE for details.