Template

Telegram webhook bot on Cloudflare Workers

Serverless webhook with constant-time secret-token check, replies in the webhook response and a protected /setup route.

Download ZIP (5.7 KB)

SHA-256: 00492049aed9526b45cb79475e64b6c5ff0c07a25fd2da39860e1105bfb45066 (checksum file)

Stack: Cloudflare Workers, no runtime dependencies · License: MIT · Files: 11

What it includes

Serverless webhook with constant-time secret-token check, replies in the webhook response and a protected /setup route.

File tree

cloudflare-telegram/
├── src/
│   ├── index.js
│   └── logic.js
├── tests/
│   └── logic.test.js
├── .dockerignore
├── .env.example
├── .gitignore
├── Dockerfile
├── LICENSE
├── package.json
├── README.md
└── wrangler.toml

Setup

unzip cloudflare-telegram.zip && cd cloudflare-telegram
npm install
cp .env.example .dev.vars
npm test
npx wrangler secret put BOT_TOKEN
npx wrangler secret put WEBHOOK_SECRET
npx wrangler deploy

Fill in .env with credentials from the platform's official developer console. Never commit it: the included .gitignore excludes it.

Step-by-step guide

  1. Download the ZIP above, check its SHA-256 and unzip it.
  2. Open @BotFather in Telegram, send /newbot and keep the token for wrangler secret put BOT_TOKEN.
  3. Copy .env.example to .env (or .dev.vars for Workers) and paste the values. Never commit it.
  4. Install dependencies and run the tests: they pass without network access.
  5. Run it locally with the commands in the Setup section and send your bot a message.
  6. Push the folder to a private GitHub repository so a host can build it.

Where to deploy

This template runs on Cloudflare Workers, not on Railway: deploy it with npx wrangler deploy and then call the protected /setup route to register the webhook.

Next steps

Run with Docker

docker build -t cloudflare-telegram .
docker run --rm --env-file .env cloudflare-telegram

Official documentation

https://core.telegram.org/bots/api#setwebhook

All templates