Telegram Serverless Is Here: Deploy Bots With Zero Infrastructure

basanta sapkota

If you've ever spun up a VPS just to handle a /start command on a Telegram bot, you know the pain. You rent a server, configure webhooks, worry about uptime, patch security updates, and keep the whole thing running 24/7 for something that processes maybe ten messages an hour. It's always felt like overkill. Telegram apparently thought so too, because they just launched Telegram Serverless, a native runtime that lets you deploy bot backends directly on Telegram's own infrastructure. No servers. No containers. One command.

This is a big deal for bot developers, and it comes with both exciting possibilities and some real tradeoffs worth thinking about.

Key Takeaways

  • Telegram Serverless runs your bot's JavaScript code in V8 isolates on Telegram's own servers, eliminating the need for any external hosting.
  • Every bot gets a built-in SQLite database that persists between invocations, with a Drizzle-like query builder.
  • Deployment is a single command: npx tgcloud push. Database migrations are handled separately with npx tgcloud migrate.
  • Cold start times for V8 isolates are typically under 5 milliseconds, far faster than Lambda's container-based approach.
  • There are real concerns around data privacy and vendor lock-in since all bot data now lives inside Telegram's infrastructure with no documented export mechanism.
  • The platform currently supports JavaScript only, with no npm packages, no filesystem access, and no WebAssembly support.

What Is Telegram Serverless?

Telegram Serverless is a managed runtime that lets you write plain JavaScript modules, deploy them through a CLI tool, and have Telegram execute them whenever your bot receives an update. As described in the official documentation, your code runs in a "fast, isolated V8 sandbox that sits right next to the Bot API and a built-in database."

The architecture is straightforward. You write handler functions (one per update type), put shared logic in a lib/ folder, and define your database schema in schema.js. When someone sends your bot a message, Telegram routes it to the matching handler, runs your function, and that's it. No webhook configuration. No long-polling. No server to monitor.

Think of it as Cloudflare Workers, but purpose-built for Telegram bots.

How the Developer Workflow Actually Works

Getting started is surprisingly fast. You need Node.js 18+ and a bot registered with @BotFather. First, enable Serverless through BotFather's bot settings, then scaffold a project:

npm create @tgcloud/bot my_bot
cd my_bot

This gives you a clean project structure:

my_bot/
├─ handlers/
│  └─ message.js      

# handles incoming messages
├─ lib/                

# shared utility code
├─ schema.js           

# database table definitions
├─ package.json
└─ docs/
   └─ tgcloud-sdk.md   

# SDK reference

Deploying is just:

npx tgcloud push       

# uploads your code
npx tgcloud migrate    

# applies database changes

That separation between code deployment and database migration is a nice touch. The CLI shows you exactly what database changes are needed, classifies them by risk level (safe, warning, or manual), and lets you review before anything happens.

A Working Bot in Under 30 Lines

Here's a complete example from the official docs. This bot replies to every message and tracks how many messages it's received from each chat:

// schema.js
import { table, integer } from 'sdk/db';

export const counters = table('counters', {
  chatId: integer('chat_id').primaryKey(),
  seen:   integer('seen').notNull().default(0),
});
// handlers/message.js
import { api, db } from 'sdk';
import { counters } from 'schema';
import { sql } from 'sdk/db';

export default async function (message) {
  const chatId = message.chat.id;

  const [row] = await db.insert(counters)
    .values({ chatId, seen: 1 })
    .onConflictDoUpdate({
      target: counters.chatId,
      set: { seen: sql`${counters.seen} + 1` },
    })
    .returning()
    .run();

  await api.sendMessage({
    chat_id: chatId,
    text: `Hello! I've seen ${row.seen} message(s) from you.`,
  });
}

That's a live bot with persistent state. No Express server, no database connection strings, no deployment pipeline to configure. If you've wrestled with webhook setups and cloud function configurations before, this simplicity is genuinely refreshing.

Why V8 Isolates Are the Right Choice Here

Telegram chose V8 isolates over traditional containers, and it's a smart technical decision. V8 isolates are lightweight execution contexts inside Google's V8 JavaScript engine (the same engine powering Chrome and Node.js). A single process can run thousands of isolates simultaneously, each with fully separated memory.

The performance difference is significant. Cold start times for V8 isolates measure in single-digit milliseconds, compared to 100-1,000+ milliseconds for AWS Lambda's container-based approach. Cloudflare Workers and Deno Deploy already proved this model works at scale.

Since Telegram's isolates run "close to Telegram's own systems," Bot API calls and database queries should be exceptionally fast. No network round trips to external services.

What You Can and Can't Do

The SDK exposes three main things: api (the Bot API), db (the SQLite database), and fetch (for calling external HTTP services). That's your entire toolkit.

What's included:

  • Full Telegram Bot API access
  • SQLite database with upserts, joins, and a typed schema DSL
  • Outbound HTTP via fetch for third-party integrations
  • Mini App backend support

What's not available (yet):

  • No npm packages or external dependencies
  • No filesystem access
  • No WebAssembly
  • No file uploads from within handlers (you can reference existing files by file_id)
  • Foreign keys are silently ignored (PRAGMA foreign_keys is disabled)

That last point about foreign keys caught my eye. If you're used to relational integrity at the database level, you'll need to enforce it in your application code instead. Not ideal, but workable.

The Privacy and Lock-In Question

I'd be doing you a disservice if I didn't mention this part. It matters.

When you deploy to Telegram Serverless, your code, your database, and all your users' interaction data live on Telegram's infrastructure. Before this, developers running bots on their own backends had full control over where user data was stored and how it was retained. That control is now gone if you use Telegram Serverless.

As Tech Times reported, regular Telegram messages (including all bot interactions) are not end-to-end encrypted. Only Secret Chats use client-to-client encryption. That's always been true for bots, but now both the processing logic and the stored data sit inside that same infrastructure.

There's also currently no documented mechanism for exporting your bot's database out of the Telegram Serverless environment. Code can be rewritten. Data is harder to move. If you're building something that needs long-term portability, keep this in mind.

For hobby projects and low-sensitivity bots? Absolutely fine. For handling medical records or financial data? Probably think twice.

Who Should Use Telegram Serverless

This platform is ideal for several categories of bots:

  • Conversational bots that need per-user state tracking
  • Mini App backends serving dynamic content
  • Games and tools with leaderboards or quizzes
  • Automation bots that call third-party APIs and push results into chats
  • Weekend projects where you just want something running fast without infrastructure overhead

If you've been curious about building Telegram bots but didn't want to deal with hosting, this removes the biggest barrier to entry. For a solid primer on vibe coding your way through bot development, check out our recent post on the topic.

Final Thoughts

Telegram Serverless is genuinely impressive as a developer experience. One command deployment, built-in database, sub-5ms cold starts, and zero infrastructure to manage. For the Telegram bot ecosystem, it's a massive quality-of-life improvement.

But go in with your eyes open. You're trading operational simplicity for platform control over your data and limited portability. For many use cases, that tradeoff is absolutely worth it. For others, sticking with a self-hosted backend or an external serverless provider like AWS Lambda or Cloudflare Workers makes more sense.

The best approach? Try it. Scaffold a project, build a simple bot, and deploy it. It'll take you fifteen minutes. Then decide if the constraints work for your specific needs.

Sources

  1. Telegram Official Documentation - Telegram Serverless
  2. Tech Times - Telegram Serverless Ships: One Deploy Command, But Your Bot Data Never Leaves Telegram
  3. Hacker News Discussion - Telegram Serverless (212 points, 105 comments)
  4. Cloudflare Blog - Eliminating Cold Starts with Cloudflare Workers
  5. freeCodeCamp - How to Build a Serverless Telegram Bot
  6. Sampo.website - Serverless Telegram Bot

Post a Comment