---
title: "Deploy Telegram Bot (Python 3.12)"
description: "Webhook Telegram bot pinned to Python 3.12. Set TELEGRAM_BOT_TOKEN."
category: "Bots"
url: https://railway.com/deploy/telegram-bot-python-312
---

# Deploy Telegram Bot (Python 3.12)

Webhook Telegram bot pinned to Python 3.12. Set TELEGRAM_BOT_TOKEN.

**[Deploy Telegram Bot (Python 3.12) on Railway](https://railway.com/template/telegram-bot-python-312)**

- **Creator:** Bhanu Vadlakonda's Projects
- **Category:** Bots
- **Total deploys:** 6

## Template content

### telegram-bot-py312

- **Source:** https://github.com/bhanuvadlakonda/telegram-bot-py312
- **Public domain:** Yes

## Documentation

# Deploy and Host Telegram Bot (Python 3.12) on Railway

[![Deploy on Railway](https://railway.com/button.svg)](https://railway.com/deploy/telegram-bot-py312)

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

- [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot)
- [Telegram Bot API](https://core.telegram.org/bots/api)
- [BotFather](https://t.me/BotFather) for `TELEGRAM_BOT_TOKEN`
- [PEP 594](https://peps.python.org/pep-0594/) (`imghdr` removed in 3.13)
- Source: [bhanuvadlakonda/telegram-bot-py312](https://github.com/bhanuvadlakonda/telegram-bot-py312)

## 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

```bash
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
```


## Similar templates

- [Telegram JavaScript Bot](https://railway.com/deploy/5lRkWa) — A template for Telegram bot in JavaScript using grammY
- [Cobalt Tools [Updated Aug ’26]](https://railway.com/deploy/cobalt) — Cobalt Tools [Aug ’26] (Media Downloader, Converter & Automation) Self Host
- [Telegram Gateway](https://railway.com/deploy/railway-telegram-gateway) — Multi-bot Telegram webhook gateway with WebSocket event streaming

Open this page in a browser: https://railway.com/deploy/telegram-bot-python-312
