Bun

Free Bun Telegram bot hosting.

grammY, Telegraf, or no library at all: Bun ships fetch, so the Bot API is one HTTP call away. Long polling, around the clock.

Libraries

Libraries that run here

grammY

The natural fit. It is written in TypeScript, and your .ts entry file runs as it is, with no compile step between editing a handler and restarting.

Telegraf

Runs from the same package.json it would use under Node. The better choice if you are following an existing tutorial, since most of them were written against it.

Plain fetch

The Bot API is HTTPS and JSON. For a bot that is three commands and a reply, a getUpdates loop over the built-in fetch is less code than configuring a framework.

Deploying

Getting it running

  1. 1

    Upload your project

    Drag the folder in or push it over SFTP, without node_modules. It is installed on deploy, and a Telegram dependency tree is small enough that the install is over almost before it starts.

  2. 2

    bun install runs for you

    Your package.json is read and installed before the bot starts. The same file works under Node, so the runtime you choose is not a commitment.

  3. 3

    Point us at your entry file

    bot.ts or index.ts, uncompiled. Your BotFather token goes into an environment variable and is read from process.env or Bun.env, never from a file you might commit.

Memory

What actually fits in 256 MB

More than you will need. A Telegram library caches nothing on your behalf, long polling holds one request open at a time, and a busy bot on Bun sits in tens of megabytes, as it would on Node.

When a Telegram bot does run out, it is session storage: the in-memory session store keeps every chat it has ever seen. Give it a TTL, or keep sessions in SQLite on your 512 MB of disk. Bun has a SQLite driver built in, so that costs no extra dependency.

The other culprit is media. Reading a whole file into memory before forwarding it holds all of it at once; writing it to disk and streaming it back out does not.

FAQ

Questions

grammY or Telegraf on Bun?

grammY if you are starting fresh. It is TypeScript through and through, which is the reason to be on Bun in the first place. Telegraf if you are bringing existing code or following a tutorial. Both long-poll happily here.

Where should sessions live?

In a file. Bun ships bun:sqlite, so a SQLite database in your project directory needs nothing added to package.json and survives restarts, crashes and redeploys.

Do I need to compile TypeScript first?

No. Point us at the .ts file and it runs. Bun strips the types without checking them, so run tsc locally if you want errors caught before the bot meets real users.

Does Bun read a .env file?

Automatically, which is convenient and worth being careful with: a .env uploaded with your code sits in your file manager like any other file. Setting the token as an environment variable keeps it out of your files entirely.