FastAPI Telegram webhook service for Дюна: Приключения в Империи dice rolls.
The old Flask/telebot PythonAnywhere app has been replaced with an async FastAPI app using python-telegram-bot. Game logic and legacy text syntax are preserved, and /roll now also opens a button-based roll wizard.
/startor/helpsends help./rollopens the interactive keyboard./roll 15 n4 c6 d3 r18 !rolls from text.- Inline mode still works:
@duneTTRPG_bot 15 n4 c6 d3 r18 !. - Inline help still works:
@duneTTRPG_bot help. - In group chats,
/rollkeyboards are visible to the group, but only the player who opened the menu can change or roll that menu.
Legacy syntax:
@duneTTRPG_bot T nX cY dZ rV !
T- порог успехаX- число кубиков, default2Y- критический успех, default1Z- сложность проверкиV- затруднения, default20!- потрачена Решимость
The app reads configuration from runtime environment variables only. It does not load .env files automatically.
| Variable | Required | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN |
yes for bot runtime | Bot token from BotFather. |
TELEGRAM_WEBHOOK_PATH_SECRET |
yes | Secret path segment for /telegram/webhook/{secret}. |
TELEGRAM_WEBHOOK_SECRET_TOKEN |
recommended | Telegram secret_token, checked from X-Telegram-Bot-Api-Secret-Token. |
PUBLIC_BASE_URL |
for webhook scripts | Public Vercel or tunnel URL without trailing slash. |
SERVICE_VERSION |
no | Runtime version, default 0.2.0. |
LOG_LEVEL |
no | Default INFO. |
See .env.example for a full template.
Install dependencies:
python -m pip install -e ".[dev]"Run tests:
python -m pytestRun the API:
uvicorn app:app --reloadHealth check:
curl.exe --noproxy * http://127.0.0.1:8000/healthTelegram supports one active webhook per bot token. Switching between local and production means setting the webhook again.
For local testing:
- Start the app with
uvicorn app:app --reload. - Expose it with a tunnel such as ngrok or cloudflared.
- Set:
$env:PUBLIC_BASE_URL="https://your-tunnel.example"
$env:TELEGRAM_BOT_TOKEN="..."
$env:TELEGRAM_WEBHOOK_PATH_SECRET="..."
$env:TELEGRAM_WEBHOOK_SECRET_TOKEN="..."
python scripts/set_webhook.pyInspect current Telegram webhook:
python scripts/get_webhook_info.pyThe repository is ready for Vercel Git deployments:
- root
app.pyexposes the ASGI app pyproject.tomldeclares Python>=3.12and runtime dependenciesvercel.jsonexcludes tests and caches from the function bundle
In Vercel Project Settings, configure the Telegram environment variables. Production branch deploys become production deployments; other branches become preview deployments. After deploying the desired URL, set the Telegram webhook with scripts/set_webhook.py.
docker compose up --build import-checksrc/app/services/dice_service.pyintentionally keeps the legacy loose parser and output spelling, includingtreshold.- Telegram group keyboards cannot be made private once posted in a group. For private parameter building before posting to a group, the likely future upgrade is a Telegram Mini App that builds a roll query and returns the user to inline mode.
- Webhook registration is never done at import time.
- PythonAnywhere proxy and absolute file paths were removed.