Deploy a Telegram bot

An always-on Telegram bot. Get a token, set it, and it's live.

A bot is a long-running worker: it talks out to Telegram and reacts to messages. Dockhold keeps it running and gives it a URL for a status page. This recipe is the whole path.

Start from thetelegram-bot-starter template: click Use this template, thendeploy it.

1. Get a bot token

In Telegram, message @BotFather, send/newbot, pick a name, and copy the token it gives you (looks like 123456789:AA...).

2. Deploy and set the token

  1. Connect the repo at the dashboard and deploy.
  2. Add BOT_TOKEN under Settings, then Secrets(it's a secret, not a plain variable), connect it to the app, then restart.

Message your bot on Telegram: /start, /help, or any text, and it echoes back. Until the token is set, the app runs idle and its URL shows a "set BOT_TOKEN" status. It never crashes.

3. Add your own commands

Edit index.js with Telegraf:

bot.command("ping", (ctx) => ctx.reply("pong"));
bot.hears("hello", (ctx) => ctx.reply("hi there"));

Keep any API keys the bot uses as secrets and read them from process.env.

How it works

The bot uses long polling (it asks Telegram for updates), so there's no webhook to configure. It also runs a small status server on0.0.0.0:$PORT. Dockhold gives every app a URL, and this gives you something to hit instead of an error. Run it as a single instance: a polling bot scaled past one replica would handle every update twice.

High volume? Switch to webhook mode. Have Telegram POST updates to your app's https://<your-app>.dockhold.app/URL on $PORT instead of polling. Discord?Same shape: swap Telegraf for discord.js and use aDISCORD_TOKEN.

Troubleshooting

  • Bot doesn't respond / logs "401 Unauthorized": theBOT_TOKEN is missing or wrong. Set the exact token from BotFather as the secret's value and restart.
  • Replies arrive twice: you're running more than one instance. A long-polling bot must be a single replica.

Next

Suggested guides
to move to openEsc to closeFrom the Dockhold docs