A sample Telegram bot and Mini App running on Telegram Serverless (tgcloud). There is no server: Telegram runs the code in tgcloud/ next to the Bot API, with a built-in SQLite database, and hosts the Mini App build at https://app<app_id>.tgcloud.ai/.
- Any message: the bot stores the sender in the
userstable, increments their message count, and replies with the running total. /start: greets the user and, onceMINI_APP_URLis set, shows an "Open stats" button./zen: fetches a line fromhttps://api.github.com/zenthrough the SDK'sfetch.- Mini App: calls the
getStatsendpoint and shows the user's count, join date, and bot-wide totals.
| Path | Purpose |
|---|---|
tgcloud/schema.js |
users table |
tgcloud/handlers/message.js |
Message handler (/start, /zen, counter) |
tgcloud/endpoints/getStats.js |
POST /api/getStats, called by the Mini App |
tgcloud/lib/ |
Shared code: user queries, GitHub Zen fetch, MINI_APP_URL |
index.html, src/ |
Vite Mini App front-end (plain JavaScript) |
tgcloud.jsonc |
Hosts the dist build folder as the Mini App |
AGENTS.md and docs/tgcloud-sdk.md are the platform's own guides, generated by npm create @tgcloud/bot.
Requires Node.js 18 or newer.
-
Create a bot with @BotFather and enable Serverless for it in BotFather's bot settings.
-
Install dependencies and link the project to the bot.
loginasks for the CLI token (app<id>:<secret>) from the BotFather Serverless menu and stores it in the gitignored.tgcloud/folder.npm install npx tgcloud login
-
Build the Mini App and deploy the code, then create the
userstable:npm run deploy npx tgcloud migrate
-
Copy the Mini App URL that
pushprinted intotgcloud/lib/config.jsand runnpm run deployagain. Optionally, set it as the bot's menu button or Main Mini App in BotFather.
npm run lint # ESLint with JSDoc rules
npm run build # build the Mini App into dist/
npx tgcloud status
npx tgcloud run handlers/message '{ chat: { id: <your chat id> }, from: { id: <your user id>, first_name: "Test" }, text: "hi" }'
npx tgcloud run endpoints/getStats '{}' --ctx '{ initData: { user: { id: <your user id> } } }'tgcloud run executes on the platform against local files without deploying, so it touches the real database and sends real messages.
Runtime limits: modules may import only sdk and other project modules (no npm packages, no filesystem), and the database has no foreign keys.