Skip to content

TelegramBotOnCloudRun

Dennis Lee edited this page May 21, 2026 · 1 revision

title: Telegram Bot Hosting on Google Cloud Run type: technique created: 2026-05-16 last_updated: 2026-05-16 related: ["Playradar", "radar/techniques/ScriptToProduct"] sources: ["https://nullonerror.org/2021/01/08/hosting-telegram-bots-on-google-cloud-run/"] radar_quadrant: Techniques radar_ring: Assess radar_position: center

Telegram Bot Hosting on Google Cloud Run

An architecture for hosting Telegram bots on Google Cloud Run using webhook mode instead of polling, enabling free-tier serverless deployment with no always-on server cost.

The Architecture

A Telegram bot can operate in two modes: polling (the bot repeatedly asks Telegram for new messages) or webhook (Telegram pushes updates to a URL when a message arrives). Polling requires a continuously running process. Webhooks work with request-driven platforms like Cloud Run, which only run when a request arrives and scale to zero between requests.

The stack:

Layer Technology
Bot framework python-telegram-bot
Web server Flask + gunicorn
Container Docker (python:3.8-slim)
Platform Google Cloud Run

The Flask app exposes a single POST / endpoint. Cloud Run receives the webhook from Telegram, passes it to the Flask endpoint, which feeds it to the python-telegram-bot Dispatcher. The response is 204 No Content.

Deployment

Deployment is a single gcloud beta run deploy command with --source ., which builds and pushes the container automatically. After deploy, the webhook URL is registered with Telegram once via the Telegram Bot API:

curl "https://api.telegram.org/bot${TOKEN}/setWebhook?url=<cloud-run-url>"

The bot token is passed as an environment variable via --set-env-vars, not baked into the image.

Free Tier Fit

Google Cloud Run's free quota (2 million requests/month, 360,000 GB-seconds compute) is sufficient for personal or low-traffic bots. The scale-to-zero behaviour means idle bots cost nothing.

Tradeoffs

Cold starts. The first request after an idle period incurs a container startup delay. For bots with infrequent use this is noticeable but acceptable.

Statelessness. Cloud Run instances are ephemeral. Any state (conversation context, user sessions) must be stored externally (Cloud Firestore, Redis, etc.) rather than in memory.

Webhook-only. Polling mode cannot run on Cloud Run's serverless model. The webhook approach is a prerequisite, not an option.

Radar Assessment

Telegram Bot on Cloud Run sits in the Assess ring of the Techniques quadrant, at center position. First exposure via the nullonerror.org article published 2021-01-08; no personal implementation as of 2026-05-16. The article provides a complete working recipe — Dockerfile, gcloud deploy command, and webhook registration via curl — meaning a trial requires minimal additional research. Center position reflects this low-friction path to implementation, balanced against the narrow applicability: the technique is only relevant when building Telegram bots, limiting its urgency relative to broader patterns.

Clone this wiki locally