Cloudflare Workers Telegram Bot
A production-grade serverless Telegram bot platform demonstrating cloud-based architecture with dynamic menu systems and state persistence.
Overview
Built on Cloudflare Workers with KV Storage for persistent state management, featuring:
- Dynamic nested reply keyboard system
- Admin management API with authentication
- Media broadcasting capabilities
- Webhook-based real-time responses
Architecture
Cloudflare Worker
├─ /webhook (Telegram updates)
├─ /api/auth (admin authentication)
├─ /api/buttons (CRUD nested menus)
├─ /api/broadcast (push to all users)
├─ Static assets (served via ASSETS)
└─ KV Storage (state persistence)
Key Features
- Dynamic hierarchical menus: Multi-level reply keyboards with CRUD operations
- Serverless architecture: Zero cold-start latency with edge deployment
- KV persistence: User state, button configurations, and metadata
- Media support: Photo, document, sticker attachments with captions
- Admin controls: Chat ID-based authentication and broadcast capabilities
- Webhook-based: Responsive, no-polling architecture
Technical Highlights
- Markdown-like authoring converted to Telegram-safe HTML
- Automatic keyboard refresh on configuration changes
- Per-user data commands (
/save,/get,/update,/delete) - Vitest test setup for reliability
API Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
/api/auth | POST | Validate admin credentials |
/api/buttons | GET/POST | List / create menu buttons |
/api/buttons/:id | GET/PUT/DELETE | Manage individual buttons |
/api/broadcast | POST | Send messages to all users |
/webhook | POST | Handle Telegram updates |