Deploy Telegram Bot (Python 3.12)
Webhook Telegram bot pinned to Python 3.12. Set TELEGRAM_BOT_TOKEN.
telegram-bot-py312
Just deployed
Deploy and Host Telegram Bot (Python 3.12) on Railway
Webhook Telegram bot pinned to Python 3.12 so it does not crash on Railpack default Python 3.13 (imghdr removed, PEP 594). Set TELEGRAM_BOT_TOKEN from BotFather and deploy. Healthcheck: GET /healthz.
About Hosting Telegram Bot (Python 3.12)
This template runs an ASGI webhook server (python-telegram-bot v21 + uvicorn) on Railway. Railpack builds Python from .python-version and RAILPACK_PYTHON_VERSION=3.12. The process binds PORT and serves /healthz even if the token is missing. When TELEGRAM_BOT_TOKEN is set, it registers https://$RAILWAY_PUBLIC_DOMAIN/webhook. No volume. No database. Webhooks fit Railway better than long polling because the service must pass an HTTP healthcheck.
Why Deploy Telegram Bot (Python 3.12) on Railway
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you do not have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying this bot on Railway you get HTTPS, a public domain, and a healthchecked webhook process without running a poller. The Python 3.12 pin avoids the Railpack 3.13 imghdr crash.
Common Use Cases
- Echo /start Telegram bots for demos and internal tools
- Webhook bots that must stay up on a PaaS with
PORT+ healthchecks - A 3.12-pinned starter if an older Telegram stack still imports
imghdr - A small production-shaped bot you can extend with more handlers
Dependencies for Telegram Bot (Python 3.12) Hosting
- Python 3.12 (
.python-versionandRAILPACK_PYTHON_VERSION=3.12) python-telegram-bot[webhooks]v21+uvicorn- Telegram Bot API token from BotFather (
TELEGRAM_BOT_TOKEN)
Deployment Dependencies
- python-telegram-bot
- Telegram Bot API
- BotFather for
TELEGRAM_BOT_TOKEN - PEP 594 (
imghdrremoved in 3.13) - Source: bhanuvadlakonda/telegram-bot-py312
Deploy
- Click Deploy on Railway.
- Set required
TELEGRAM_BOT_TOKENfrom BotFather. - Keep
RAILPACK_PYTHON_VERSION=3.12. - Railway injects
PORTandRAILWAY_PUBLIC_DOMAIN. The bot setshttps://$RAILWAY_PUBLIC_DOMAIN/webhook. GET /healthzreturns 200 even without a token (process still bindsPORT).
Local run
python3.12 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt
PORT=8080 python main.py
curl -sS http://127.0.0.1:8080/healthz
Template Content
telegram-bot-py312
bhanuvadlakonda/telegram-bot-py312TELEGRAM_BOT_TOKEN
RAILPACK_PYTHON_VERSION
