Telegram Widget Bot
Telegram Widget Bot (AZiPA/telegram-widget-bot) is a modular Profile 1 Chat Widget Engine built for Telegram Serverless (@tgcloud/cli ^0.2.0). Written in pure JavaScript ESM ("type": "module"), it executes inside stateless V8 isolates backed by built-in SQLite (sdk/db) with zero runtime node_modules and zero Node.js built-ins inside tgcloud/.
The backend-only codebase spans 43 modular .js files providing a Profile 1 Chat Widget Engine, 3 built-in interactive Mini-HTML Chat Widgets, a live custom .html widget validator and sandbox launcher, and 3 Mini App POST /api/* API endpoints (no static Mini App frontend is configured in tgcloud.jsonc). Its in-Telegram bot UI is English-only (en-US) with no internal i18n dictionary, while documentation and repository READMEs are bilingual in English and Persian (MPL-2.0).
High-Level Update & Widget Flow
Section titled “High-Level Update & Widget Flow”flowchart LR Entry["User Command, .html Upload, or Inline Deep Link"] --> Isolate["Telegram Serverless (V8 Isolate & 3 Handlers)"] Isolate --> Engine["Widget Engine & Profile 1 Validator"] Engine <--> Storage["2-Table SQLite & Telegram sendWidget API"]
Core Highlights
Section titled “Core Highlights”1. Three Built-In Profile 1 Mini-HTML Widgets
Section titled “1. Three Built-In Profile 1 Mini-HTML Widgets”- Stopwatch (
/timer [title]): An offline client-only widget (isShared: false,allowQueries: false,width: 0,height: 550) with an Analog SVG dial and DigitalHH:MM:SS.dlap table, haptic feedback (HapticFeedback.impactOccurred('light')),localStorage/sessionStoragepersistence (100laps max), and zero SQLite writes. - Live Shared Poll (
/poll Question | Option 1 | Option 2 ...): Supports2–5pipe-separated options with dual-mode persistence—per-messagewidget_instanceswhenALLOW_SHARED_WIDGETSisfalse, orshared_widgets+editSharedWidgetData(cacheTime: 15s) when enabled—protected by monotonic revisionrand Commit-After-Edit ordering. - Tap Duel (
/duel [target]): A turn-based 2-player tap duel (targetclamped3–15, default5) stored inchatData, with a forwarded read-only snapshot summary inpublicData.summary.
2. Live Custom .html Validator & Sandbox
Section titled “2. Live Custom .html Validator & Sandbox”Private-chat users (or allowlisted IDs via CUSTOM_UPLOAD_ADMIN_IDS) can upload .html, .htm, or text/html files up to 65,536 B (64 KB). The engine parses <!-- @tg-widget {...} --> directives and caption flags, minifies HTML, verifies Profile 1 size, DOM depth, tag count, and network-API rules using V8 web standards (CompressionStream('deflate')), launches the widget, and routes sandbox queries (chat:<json>, state:<json>, or JSON echoes) automatically.
3. Auto-Registered Modular Engine
Section titled “3. Auto-Registered Modular Engine”Authoring a new built-in widget requires only a folder under tgcloud/lib/widgets/definitions/<type>/ with pure state.js and template.js modules. Running node scripts/validate-widgets.js automatically discovers definitions, regenerates tgcloud/lib/widgets/registry/catalog.js, and enforces raw (<= 32,768 B) and zlib-9 (<= 4,096 B) Profile 1 budgets.
4. Dynamic Launch Menu, Inline Mode & Mini App APIs
Section titled “4. Dynamic Launch Menu, Inline Mode & Mini App APIs”- Dynamic
/share& Deep Links:/sharegenerates inline launch buttons fromcatalog.js, and/start launch_<type>deep-links directly into launching any registered widget. - Inline Launcher (
@bot [query]): Filters widgets bytype,title, ordescriptionand servesarticledeep-link cards (https://t.me/<bot>?start=launch_<type>). - Fail-Closed Mini App Endpoints: Three
POST /api/*routes (/api/listWidgets,/api/sendWidget,/api/widgetQuery) validatectx?.initData?.userstrictly before dispatching or mutating widgets.
5. Single-Secret CI/CD Pipeline
Section titled “5. Single-Secret CI/CD Pipeline”The included GitHub Actions workflow validates every widget against Profile 1 budgets and deploys to Telegram Serverless on Node.js 26 using only one repository secret: TGCLOUD_TOKEN (app<id>:<secret>).
Next Steps
Section titled “Next Steps”- Setup & Deployment — Review
@BotFathersetup, single-secret GitHub Actions CI, and local@tgcloud/clicommands. - Widgets, Commands & Uploads — Explore Stopwatch, Poll, Tap Duel, commands, inline deep links, and custom
.htmluploads. - Widget Engine & Authoring — Learn the modular engine internals, Profile 1 budgets, and how to add new widgets.
- Configuration, Schema & API — Inspect
WIDGET_CONFIG, handlers, the 2 SQLite tables, and Mini App APIs.