Telegram Serverless: run a bot and host a Mini App without your own VPS
A practical guide to BotFather, tgcloud, handlers, the database and Mini App hosting. Includes a downloadable example and 14 offline tests.

Telegram Serverless hosts a bot's JavaScript handlers and the backend of its Mini App on Telegram's infrastructure. Once you deploy a handler, Telegram invokes it when a matching event arrives. Your laptop can be off when a customer asks for a quote. A separate VPS, a reverse proxy and a continuously running bot process are unnecessary for this particular architecture.
Pavel Durov highlighted building and managing bots from a phone at Blockchain Life on December 2. The platform already had a history before the keynote: Telegram dates the addition of Mini App front-end hosting to October 6. We checked official CLI 0.2.0, created an empty local project and tested a small handler's business logic. The guide separates those tests from the steps that publish to your bot. Conference announcement · Telegram Serverless documentation.
What it means for a bot to live in the cloud
Consider a bot that accepts /quote 3. Telegram passes a message object to a JavaScript function. The function reads the quantity, calculates a reply and asks the Bot API to deliver it. After the function returns, nothing has to remain running on your own computer. If the bot should remember an order when the customer returns tomorrow, write it to the database. A module-level variable is a poor substitute for persistent storage.
The runtime executes modules inside an isolated V8 environment. Its SDK provides the Bot API, an SQLite-backed database and outbound HTTP. That fits a small intake workflow, a service that checks order status, or a Mini App that displays an outstanding balance. It is not a drop-in container host for an existing Python process and arbitrary system packages. A separate service can still handle video processing or local inference while the bot serves as the user interface.
Set up a workspace on a computer
- Use a test bot. Create one in the official BotFather. Open that bot's settings and turn on Serverless. If your existing bot already serves customers, start with a separate username so a practice command will not change its behaviour.
- Install Node.js 18 or newer. Check
node --versionandnpm --version. Run the following in a directory where you can create a project. The local namequote-demois independent of the public bot username. - Link the workspace when you are ready. Obtain the CLI access token from Serverless → CLI Access in BotFather. It is separate from the usual Bot API token. Run
npx tgcloud logininside the project and enter it at the prompt. Keep credentials out of handlers, example archives and chats with contractors.
npm create @tgcloud/bot quote-demo
cd quote-demo
npx tgcloud status
npx tgcloud diff
The generated project uses tgcloud/handlers/ for bot updates, tgcloud/lib/ for shared code and tgcloud/schema.js for the database definition. Use endpoints/ for functions called by a Mini App. A scaffold also includes SDK guidance and an AGENTS.md. If you work with a coding assistant, open the generated project and point it to those conventions. It can then work within the actual module structure instead of inventing an HTTP server that the platform never starts. Project structure.
A quote bot with an offline test
The series download contains a serverless directory. One fictional unit costs 250. Send /quote 3 and the expected response is 750 demo units. Zero, a decimal, or more than 999 should produce a usage hint. A photo without text is ignored. The handler also ignores group chats, so send your first real test in a private conversation with the bot.
Extract the kit, change into its serverless directory and run node --test test.mjs. No Telegram token or network connection is needed. We ran nine cases on Node 22. All nine passed, covering normal input, both boundaries, whitespace, invalid values and an absent text field. We also generated a clean project using the official tgcloud init --no-git, copied the example into it and inspected status and diff. It showed new modules and correctly reported that the project had no cloud snapshot. We did not deploy a public demonstration bot or send a Telegram message from it.
The calculation lives in lib/estimate.js. Its replyTo function takes text and returns a reply, without reading a database or contacting another person. The platform handler in handlers/message.js checks the chat type, calls that function and sends its result using the SDK. That separation makes a pricing change cheap to test. No language model needs to guess how to multiply a validated quantity by a fixed unit price.
Deploy and check the actual response
Copy only tgcloud/handlers/message.js and tgcloud/lib/estimate.js from the kit into the corresponding locations in your official scaffold. Keep the scaffold's package file, project settings and authentication files. Inspect npx tgcloud diff. You should recognise the new handler and the local module it imports. If the diff includes unexpected removals or another application's files, check the directory and linked bot before proceeding.
Run npx tgcloud push. This calculation creates no tables and needs no migration. Open the bot in Telegram, press Start, send /quote 3 and then /quote 0. The first checks the happy path. The second catches broken input handling. Close your terminal and send another valid quantity. A fresh reply is a much stronger check of the deployment than a successful local syntax check.
The CLI also offers npx tgcloud run. It executes your local code on the platform with the supplied test payload. That is different from the offline Node tests in our kit. If a handler calls a send method it can have a real effect, so use your own test chat when trying that integration. CLI reference.
Add storage and a Mini App
An order list needs durable state. Define a table in schema.js with fields such as the user ID, request number and status. Write the lookup so that the calling user sees only their records. First push the modules and schema description. Apply the database changes separately with npx tgcloud migrate after reviewing the plan. Create a test record, close the client and ask for it again. A second test account should see its own list.
A Mini App adds a front end, such as a card displaying an order and a refresh button. Its code might be plain HTML or the output of a framework build. Configure its build directory in the project. After deployment, Telegram provides an address in the form https://app<app_id>.tgcloud.ai/. Use the address printed for your project in BotFather. Open the screen from Telegram so you also test the Mini App context.
Place the function called by the screen under tgcloud/endpoints/. The official client SDK provides Telegram.WebApp.Serverless.call. For example, a My Orders button could call an endpoint that uses the supplied user context to retrieve permitted rows. Successfully loading HTML does not establish that the refresh button works. If an older screen appears, rebuild your front end. A plain push uploads the files already present in the build directory. Mini App Serverless API.
The download includes the Mini App itself. In addition to the two bot files, copy tgcloud/endpoints/quote.js and the dist/ directory. Add "static": {"source": "dist"} to tgcloud.jsonc. The two front-end files in dist are already usable, so this example has no build stage. After deployment, set the Mini App URL for the linked bot and open it from Telegram.
Enter 3 and press Calculate. The client passes the quantity to the quote endpoint. The expected result is 750 demo units, the same as in the bot chat. Outside Telegram the sample explains where to open it. If the screen loads but the calculation fails, check the endpoint name, the deployment and which bot launched the Mini App. Telegram's SDK automatically sends the initialization data, and the platform validates it before running the endpoint. If you extend the example to handle real orders, the handler still needs to restrict access to the caller's own records.
We checked five Mini App cases locally: a valid quote, rejected input, display of the reply, opening in an ordinary browser, and retry after an error. The interface check used a test substitute for the SDK. It did not deploy the example to Telegram. Run all 14 cases with node --test test.mjs miniapp-test.mjs.
Working from a phone and estimating cost
BotFather exposes handlers, database controls, Mini App files and CLI access. On a phone you can inspect a small handler, test it with a sample input and review console output. Saving some changes there deploys them immediately. Keep a reviewed project copy on your computer when working for a customer so you know what changed and can restore it.
Durov presented the infrastructure as free for developers. This example does not need a separate VPS. A paid AI provider, CRM or document processing service still has its own billing. Price out the actual integrations and their quotas individually. For a first version the useful milestone is one correct request written and returned, rather than a forecast for hypothetical traffic.
FAQ
Can I move an existing bot simply by turning Serverless on?
Review each handler and dependency first. An existing Python process, operating-system tools and continuous background tasks will not all fit the JavaScript module model. Move one function into a test project and check its behaviour before routing real users to it.
Where does the coding assistant run?
A development assistant can write the project in your editor. The deployed bot handlers run on Telegram. If the finished bot itself should call an AI model, decide which provider it uses and who pays for inference.
When is n8n a better fit?
Serverless is a natural starting point when Telegram is the main interface and a few small handlers own the workflow. If the process spans email, a CRM and several business systems, compare it with a working n8n intake example.
More from the presentation
Dictator for Mac · Newsfeed · Translation and tone · On-device dictation.
Tools
Tools
Tools