How to host a Telegram bot 24/7 for free
Why use the official Telegram API
Unlike other platforms, Telegram offers an official, free bot API — with no risk of violating the terms of service (ToS) for automation. This makes Telegram one of the most worry-free environments to host bots: you create, host, and keep it online without fear of bans for using the API as intended.
1. Create your bot in BotFather
- On Telegram, search for @BotFather (the official creation bot).
- Send the
/newbotcommand. - Choose a name and a username (which must end in
bot). - BotFather will hand you a token — keep it safe.
2. Protect your token
The token is your bot's access key. Never expose it:
- Don't push the token to GitHub.
- Store it in an environment variable (e.g.,
TELEGRAM_TOKEN). - If it leaks, use
/revokein BotFather to generate a new one.
3. Prepare your project
Pick a library for the language you prefer:
- Node.js:
node-telegram-bot-apiortelegraf. - Python:
python-telegram-botoraiogram.
Minimal example with telegraf (Node.js):
const { Telegraf } = require('telegraf');
const bot = new Telegraf(process.env.TELEGRAM_TOKEN);
bot.start((ctx) => ctx.reply('Bot online on Square Cloud!'));
bot.launch();
4. Webhook or polling?
- Polling: the bot asks Telegram if there's anything new. Simpler to set up — great to start.
- Webhook: Telegram sends updates to a public URL of your bot. More efficient for large bots.
For most cases, start with polling.
5. Deploy and keep it 24/7
- Create the
squarecloud.appfile with your application's info. - Set the
TELEGRAM_TOKENenvironment variable. - Send the project via the Dashboard or the CLI.
- Done: Square Cloud keeps your bot online 24 hours a day.
Keeping your bot resilient
Bots that run all the time need to handle errors and reconnections well. For stability best practices, see How to keep bots online 24/7. If you're starting from scratch, also check out What is deploy? How to put your application online.
Updated on: 06/13/2026
Thank you!
