TypeScript · 2022

Telegram Bot for Cloudflare Workers

A lightweight, type-safe Telegram bot framework for Cloudflare Workers: handlers chain off the incoming Request, middleware runs before them, and one URL registers the webhook. 215 forks and 120 releases on npm.

View sourceRead the docs

Fig. 1 — The package page and a Worker that hands its fetch handler to the bot.

The problem

Run a useful Telegram bot without a persistent server while keeping webhook handling, shared types and the companion web application deployable together.

Architecture

  • The Worker’s fetch receives Telegram’s webhook and hands the Request to the bot, which dispatches to typed handlers.
  • Middleware runs before the handlers, and the shared package keeps the bot and its web app on one set of types.
  • A visit to /<token>/setWebhook registers the Worker with Telegram, so there is no deploy-time CLI step to go live.

Highlights

  • 215 forks and 120 releases on npm, under Apache-2.0
  • No runtime dependencies beyond the type definitions
  • Separate development and production Worker bindings, with a consumer template to start from

Technology

TypeScript · cloudflare · telegram · npm

← All selected work

Need something like this?

Let’s scope it.

Custom websites and Telegram bots, scoped per project and quoted by email.

See servicesGet in touch