Bot Uptime

How to Host a Telegram Bot 24/7 for Free (Python & Node.js + Webhooks)

Bot Uptime containers connect directly to api.telegram.org over HTTPS with zero extra firewall setup. Whether you build a fast community helper with python-telegram-bot or an interactive mini-app backend with Node.js grammY, you can run your Telegram bot 24/7 on the Free plan using long polling, or attach a Free HTTPS Subdomain (*.apps.botuptime.net) on Developer & Pro for instant webhooks.

1. Create Your Bot Token with @BotFather

Open Telegram, search for @BotFather, send /newbot, pick a display name and a username ending in "bot", and copy the HTTP API token BotFather returns. Store that token strictly inside a .env file in your container as TELEGRAM_TOKEN — never commit it to GitHub.

2. Option A: Python (python-telegram-bot v21)

Create a Python container in your dashboard, upload requirements.txt (containing python-telegram-bot==21.10 and python-dotenv) and main.py below, add your TELEGRAM_TOKEN to .env, and click Start. Long polling works immediately on every plan including Free (~35 MB RAM).

main.py
import os
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes

load_dotenv()

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    await update.message.reply_text("Hello! Hosted 24/7 on Bot Uptime.")

def main() -> None:
    app = Application.builder().token(os.environ["TELEGRAM_TOKEN"]).build()
    app.add_handler(CommandHandler("start", start))
    app.run_polling(allowed_updates=Update.ALL_TYPES)

if __name__ == "__main__":
    main()

3. Option B: Node.js 22 (grammY)

Prefer JavaScript or TypeScript? Create a Node.js 22 container, list grammy and dotenv in package.json, and deploy index.js. On Developer or Pro plans, you can also enable an automatic HTTPS subdomain under the Domains tab and call bot.api.setWebhook("https://your-slug.apps.botuptime.net/webhook").

index.js
require('dotenv').config();
const { Bot } = require('grammy');

const bot = new Bot(process.env.TELEGRAM_TOKEN);

bot.command('start', (ctx) => ctx.reply('Online 24/7 on Bot Uptime!'));
bot.command('ping', (ctx) => ctx.reply('Pong!'));

bot.catch((err) => console.error('[Telegram Error]', err));
bot.start();

Frequently Asked Questions

Does Telegram long polling work on the Free plan?

Yes! Long polling only makes outbound HTTPS calls to api.telegram.org and runs smoothly under 40–60 MB RAM on the Free 256 MB plan.

Can I use Telegram Webhooks with HTTPS?

Yes — on Developer and Pro plans, claim a free *.apps.botuptime.net HTTPS subdomain (or link your own custom CNAME domain) in the Domains tab and listen on process.env.SERVER_PORT.

Ready to deploy your bot 24/7?

Launch a custom Discord, Telegram, or WhatsApp container (Python, Node.js, Java, Rust) with Managed Databases and Free AI Agents — or deploy a ready-made Discord bot in 1 click on Bot Uptime.