Telegram bots ยท Telegraf

Telegraf bot hosting, deployed from GitHub

Telegraf has run Node.js Telegram bots for years and its launch() call is all a long-running host needs. Push the repository, set BOT_TOKEN, deploy; the bot polls, restarts if it exits and redeploys on every commit.

Free
256 MB, always on, no card
Starter
1 GB, $2/mo or $20/yr
Standard
2 GB, $3/mo or $30/yr
Pro
4 GB, $6/mo or $60/yr

A minimal Telegraf bot that deploys as is

const { Telegraf } = require("telegraf");

const bot = new Telegraf(process.env.BOT_TOKEN);
bot.start((ctx) => ctx.reply("Hello from FadeHost"));
bot.launch();

process.once("SIGTERM", () => bot.stop("SIGTERM"));

The SIGTERM line matters: a redeploy stops the old process with SIGTERM, and a bot that handles it finishes the update it is on instead of dropping it.

Sessions, scenes and files

Telegraf's in-memory session is lost on restart; a file session under /data or a Redis session against a managed Redis keeps it. Scenes and wizards work unchanged. Files your bot downloads belong under /data too; everything else is rebuilt on deploy.

Webhooks with Telegraf

bot.launch({ webhook: { domain: "https://name.fadehost.app", port: Number(process.env.PORT) } }) serves the webhook on the panel's port. It needs a web address that stays up, which is a paid app; on the free tier keep plain bot.launch().

Frequently asked questions

Telegraf 3 or 4?

Both run. Version 4 is current; version 3 code works when you pin telegraf@3 in package.json.

Polling or webhook?

Polling works everywhere and needs nothing but the token: the bot asks Telegram for updates. A webhook needs a public https address; every hosted app has one at name.fadehost.app with its plan, but on the free tier that address sleeps when idle, so polling is the simpler choice for a free bot and a webhook is for a paid app that stays up.

Where does the token go?

In the environment variables of the app, as BOT_TOKEN or whatever name your code reads, never in the repository. The panel masks the values and injects them when the bot starts.

What happens when I push a commit?

With auto-deploy on, every push to the branch you chose redeploys the bot: install, build if there is one, start. The live console shows each step and the crash doctor explains a failed start in plain words.

What does the free tier include?

One bot with 256 MB of RAM, always on, placed where there is room for it (a paid plan picks the region), with the live console, environment variables and redeploys on push. A second bot or more memory is the Starter plan at $2 a month.

Related

Telegraf bot hosting, deployed from GitHub

Deploy a Telegraf bot free