Worker Telegram Bot Template

A minimal Telegram bot template for Cloudflare Workers, written in TypeScript and deployed with Wrangler.

Active Pure Nim score 65/100 · last commit 2026-10-09 · 1 stars · tests present · no docs generated

Summary

Latest Version Unknown
License Unknown
CI Status Failing
Stars 1
Forks 0
Open Issues 0
Last Commit 2026-10-09
Downloads 0
Last Indexed 2026-11-23 09:07

Installation

nimble install Worker Telegram Bot Template
choosenim install Worker Telegram Bot Template
git clone https://gitlab.com/AlexNottaBen-Templates/worker-telegram-bot-template

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
Worker Telegram Bot Template ✓ ✓ ✓ - - - - - - -

README

🤖 Worker Telegram Bot Template

A minimal Telegram bot template for Cloudflare Workers, written in TypeScript and deployed with Wrangler.

The Worker receives Telegram webhook updates, routes commands, and replies through the Telegram Bot API. It includes examples for text replies, images, stickers, and debugging raw Telegram updates.

✨ Features

  • Cloudflare Workers runtime with TypeScript.
  • Telegram webhook handler for incoming bot updates.
  • Secret-based BOT_TOKEN configuration.
  • Simple command routing in src/request-handler.ts.
  • Small Telegram API wrapper in src/api/telegram-bot.ts.
  • Example commands for /start, /help, /about, /image, and /sticker.

📁 Project Structure

.
├── src/
│   ├── api/telegram-bot.ts      - Telegram Bot API helper
│   ├── constants/messages.ts    - Reply text builders
│   ├── request-handler.ts       - Main webhook routing logic
│   ├── types/                   - Environment and Telegram types
│   └── worker.ts                - Cloudflare Worker entry point
├── package.json                 - npm scripts and dev dependencies
├── wrangler.jsonc               - Cloudflare Worker configuration
└── README.md

✅ Prerequisites

  • Node.js and npm.
  • A Cloudflare account.
  • A Telegram bot token from @BotFather.
  • Wrangler authentication configured with npx wrangler login.

🚀 Quick Start

Install dependencies:

npm install

Start the local Worker:

npm run dev

The local Worker responds to browser requests with:

🤖 The bot is working!

Telegram webhooks require a public HTTPS URL, so deploy the Worker before connecting it to Telegram.

🔐 Configure Secrets

Store your Telegram bot token as a Cloudflare Worker secret:

npx wrangler secret put BOT_TOKEN

Paste the token from BotFather when prompted. Do not commit the token to source control.

☁️ Deploy

Deploy the Worker:

npm run deploy

Wrangler prints the deployed Worker URL. With workers_dev enabled in wrangler.jsonc, it usually looks like:

https://worker-telegram-bot-template.<your-subdomain>.workers.dev

🔗 Set The Telegram Webhook

Tell Telegram to send bot updates to your deployed Worker URL:

curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://worker-telegram-bot-template.<your-subdomain>.workers.dev"

Check the webhook status:

curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getWebhookInfo"

To disconnect the webhook:

curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/deleteWebhook"

💬 Built-In Commands

Command Behavior
/start Greets the user.
/help Lists supported commands.
/about Sends the raw Telegram update JSON. Useful while developing.
/image Sends an example image.
/sticker Sends an example sticker.
Any other text Echoes the message with a default response.

🛠️ Customize The Bot

Most bot behavior lives in src/request-handler.ts.

Add a command by extending the command checks:

if (text === "/ping") {
    reply = "pong";
}

Update reusable message text in src/constants/messages.ts.

Add Telegram API methods in src/api/telegram-bot.ts when you need more capabilities, such as editing messages, sending documents, or managing inline keyboards.

📜 Scripts

Command Description
npm run dev Start a local Wrangler development server.
npm run start Alias for local development.
npm run deploy Deploy the Worker to Cloudflare.

🧪 Local Testing Notes

You can open the local Worker in a browser to confirm the Worker is running, but Telegram will not send webhooks to a private local URL.

For full webhook testing, deploy the Worker or expose local development through a trusted HTTPS tunnel, then set the Telegram webhook to that public HTTPS URL.

🧯 Troubleshooting

Problem Check
Bot does not reply Confirm BOT_TOKEN is set with npx wrangler secret put BOT_TOKEN.
Webhook is not called Run getWebhookInfo and verify the webhook URL is correct.
Telegram returns API errors Check Worker logs and the error logged by TelegramBot.
Commands do not match Telegram command text must exactly match strings like /start.
HTML formatting fails Replies use parse_mode: HTML, so escape user-controlled HTML if you add richer formatting.

🔍 Logs And Observability

Observability is enabled in wrangler.jsonc. During development, use Wrangler logs and the local dev output to inspect requests and errors.

For production debugging, check Cloudflare Workers logs and Telegram getWebhookInfo for delivery errors.

📚 Useful Links