Railway

Deploy Telegram Bot (Python 3.12)

Webhook Telegram bot pinned to Python 3.12. Set TELEGRAM_BOT_TOKEN.

Deploy Telegram Bot (Python 3.12)

Just deployed

Deploy and Host Telegram Bot (Python 3.12) on Railway

Deploy 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-version and RAILPACK_PYTHON_VERSION=3.12)
  • python-telegram-bot[webhooks] v21+
  • uvicorn
  • Telegram Bot API token from BotFather (TELEGRAM_BOT_TOKEN)

Deployment Dependencies

Deploy

  1. Click Deploy on Railway.
  2. Set required TELEGRAM_BOT_TOKEN from BotFather.
  3. Keep RAILPACK_PYTHON_VERSION=3.12.
  4. Railway injects PORT and RAILWAY_PUBLIC_DOMAIN. The bot sets https://$RAILWAY_PUBLIC_DOMAIN/webhook.
  5. GET /healthz returns 200 even without a token (process still binds PORT).

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

More templates in this category

View Template
Telegram JavaScript Bot
A template for Telegram bot in JavaScript using grammY

Agampreet Singh
294
View Template
Cobalt Tools [Updated Aug ’26]
Cobalt Tools [Aug ’26] (Media Downloader, Converter & Automation) Self Host

shinyduo
268
View Template
Telegram Gateway
Multi-bot Telegram webhook gateway with real-time WebSocket event streaming

INAPP
5