Blog How to Host a Telegram Bot on Replit for Free (2026)
Editorial

How to Host a Telegram Bot on Replit for Free (2026)

Admin {{ $post->author->username }} 6 min read

How to Host a Telegram Bot on Replit for Free (2026)

Replit is a cloud-based development environment that lets you write, run, and host code entirely in the browser — no local setup required. For beginner bot developers or those who want a quick deployment without managing a VPS, Replit offers a low-friction path to getting a Telegram bot online. This guide walks through the complete process in 2026.

Also see the Developer Tools category for more bot development resources and our guide on automating Telegram workflows with n8n.

Why Use Replit for Telegram Bots?

Replit's appeal for bot hosting comes down to five things:

  • Zero infrastructure management: No VPS setup, no SSH, no nginx configuration. Write code and click Run.
  • Browser-based IDE: Full development environment accessible from any device, including tablets.
  • Free tier: Replit's free plan provides a shared container with 0.5 vCPU and 512 MB RAM — more than enough for a lightweight Telegram bot.
  • Built-in secrets management: Store your bot token in Replit's Secrets (environment variables) without exposing it in your code.
  • Public URL: Every Replit receives a public .replit.app subdomain, making webhook setup straightforward.

Limitations to be aware of: Free Replit containers sleep after inactivity (typically 30 minutes without a web request). A sleeping bot won't respond to messages until the container wakes up (takes 10-30 seconds). The Hacker plan ($7/month) removes sleep restrictions for "always-on" deployments.

Setting Up Your Telegram Bot on Replit

Step 1: Create a Replit account and new Repl

  1. Go to replit.com and sign up for a free account.
  2. Click "Create Repl" → select Python (or Node.js) as the template.
  3. Name your Repl (e.g. "my-telegram-bot") and click Create.

Step 2: Store your bot token securely

  1. In the left panel of the Replit editor, click the lock icon ("Secrets").
  2. Click "New Secret".
  3. Key: BOT_TOKEN, Value: your token from @BotFather.
  4. Click "Add Secret".

Your token is now accessible as os.environ["BOT_TOKEN"] in Python or process.env.BOT_TOKEN in Node.js — never visible in source code.

Step 3: Write your bot code

For Python, paste this into main.py:

import os
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters

async def start(update: Update, context):
    await update.message.reply_text(
        f"Hello, {update.effective_user.first_name}! I'm running on Replit."
    )

async def echo(update: Update, context):
    await update.message.reply_text(f"You said: {update.message.text}")

def main():
    token = os.environ["BOT_TOKEN"]
    app = Application.builder().token(token).build()
    app.add_handler(CommandHandler("start", start))
    app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
    print("Bot is running...")
    app.run_polling(drop_pending_updates=True)

if __name__ == "__main__":
    main()

For Node.js, in index.js:

const { Bot } = require("grammy");

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

bot.command("start", (ctx) =>
  ctx.reply(`Hello, ${ctx.from.first_name}! Running on Replit.`)
);
bot.on("message:text", (ctx) => ctx.reply(`You said: ${ctx.message.text}`));

bot.start();
console.log("Bot started on Replit");

Step 4: Install dependencies

Replit installs Python packages via the Packages tool (search for python-telegram-bot) or via the Shell tab:

# Python
pip install python-telegram-bot

# Node.js (in Shell tab)
npm install grammy

Step 5: Run the bot

Click the green "Run" button. The console shows "Bot is running..." and your bot is live. Test it by sending /start in Telegram.

Keeping Your Bot Alive 24/7 on Replit

The free tier sleeps after inactivity. Two approaches to keep it alive:

Approach 1: UptimeRobot (Free)

UptimeRobot pings your Replit's public URL every 5 minutes, preventing it from sleeping. Here's how to set it up:

  1. Add a simple HTTP server to your bot that responds to pings:
# Add to your Python bot alongside the main bot code
# Run in a separate thread
from flask import Flask
from threading import Thread
import os

keep_alive_app = Flask(__name__)

@keep_alive_app.route("/")
def home():
    return "Bot is alive!", 200

def run_web():
    port = int(os.environ.get("PORT", 8080))
    keep_alive_app.run(host="0.0.0.0", port=port)

def keep_alive():
    t = Thread(target=run_web)
    t.daemon = True
    t.start()
# In main.py, call keep_alive() before app.run_polling():
from keep_alive import keep_alive
keep_alive()
# Then run your bot...
  1. Sign up at uptimerobot.com (free).
  2. Add a new monitor: HTTP(s) monitor, URL = your Replit's public URL (e.g. https://my-telegram-bot.username.repl.co), interval = 5 minutes.

Approach 2: Upgrade to Replit Hacker/Core Plan

The Replit Hacker plan ($7/month) or Core plan includes "Always On" deployments that never sleep. For a production bot with real users, this is the cleanest solution — no hack required.

Replit vs Other Free Hosting Options

Platform Free Tier Always On Setup Difficulty Best For
Replit Yes (sleeps) Paid ($7/mo) Very easy Beginners, learning
Railway $5 credit/month Yes Easy Small production bots
Render Yes (sleeps) Paid ($7/mo) Easy Docker deployments
Fly.io Yes (3 VMs) Yes Moderate Production, Docker
Oracle Cloud Free Always free (2 VMs) Yes Hard (VPS setup) Production, long-term
Cloudflare Workers 100k req/day Yes Moderate Stateless/serverless

For a beginner building their first bot: Replit. For a bot with 100+ daily users that needs reliable uptime: Railway or Fly.io. For a large-scale bot with thousands of users: a proper VPS (Oracle Cloud free tier or a paid VPS from Hetzner/DigitalOcean).

FAQ

Can I use Replit for a webhook-based bot?

Yes. Every Replit has a public .replit.app URL that works with Telegram webhooks. Set your webhook to https://your-repl.username.repl.co/webhook and configure your bot to listen for HTTP POST requests at that path. The URL is stable as long as your Repl exists.

My bot stops responding after a few hours. What's happening?

Your Replit container is sleeping due to inactivity. Implement the keep-alive web server + UptimeRobot approach described above, or upgrade to a paid plan for Always On functionality.

Is Replit secure enough for a Telegram bot with real users?

For personal projects and bots with small audiences, yes. For bots that handle sensitive data or financial transactions, use a dedicated VPS where you have full control over the environment, access logs, and security configuration.

Can I use a database on Replit?

Yes. Replit provides a built-in key-value database (from replit import db) that persists across runs. For relational data, you can use SQLite (persisted in your Repl's storage) or connect to an external database like Supabase or PlanetScale via their free tiers.

What happens to my bot when I close the Replit browser tab?

The Repl continues running for up to 30 minutes (free tier) or indefinitely (paid with Always On) after you close the tab. Your bot keeps working — closing the editor doesn't stop the process unless the container sleeps.

Share this article

Share on X