How to Host a Telegram Bot 24/7: The Complete Guide
Keep a Telegram bot online around the clock — how Telegram delivers updates, hosting options, a full deployment walkthrough and a production checklist.
On this page
Telegram bots are easy to start: talk to BotFather, get a token, run a script. Keeping one running reliably for months is a different job. This guide explains how Telegram delivers messages to your bot, what 24/7 hosting really requires, and how to deploy a bot so it stays online through crashes, restarts and updates.
How Telegram talks to your bot
Unlike Discord, Telegram bots don’t hold a permanent gateway connection. Instead, your bot receives updates — new messages, button presses, inline queries, payments — in one of two ways:
- Long polling. Your bot repeatedly calls
getUpdates, and Telegram holds each request open until an update arrives or a timeout passes. It’s simple, needs no domain or TLS certificate, and every library supports it. - Webhooks. You register an HTTPS URL with
setWebhook, and Telegram sends each update to it as a POST request. There’s no polling loop, but you need a public HTTPS endpoint.
Both are production-ready. The choice is covered in depth in long polling vs webhooks. What matters for hosting is that either way, your bot needs a process that’s always running — a polling loop that never stops, or a web server that’s always listening.
What 24/7 hosting requires
- A persistent process. Many free platforms suspend processes that don’t receive web traffic. A long-polling bot receives no inbound traffic at all, so it gets suspended — and stops answering.
- Automatic restarts. Something must restart the bot within seconds if it crashes.
- Persistent storage. Session files, SQLite databases and state must survive restarts and redeploys. This is critical for Telethon and Pyrogram, which store login sessions in files.
- Safe secrets. The bot token must be available to the process without living in your code.
- Low latency to Telegram. Every update and reply is a round trip to Telegram’s servers.
Choosing where to host
| Option | Always on | Persistent files | Effort |
|---|---|---|---|
| Your PC | Only while it’s on | Yes | Low, but unreliable |
| Free web PaaS | Often sleeps when idle | Sometimes reset on deploy | Low |
| VPS | Yes | Yes | You manage the OS and supervision |
| Managed bot hosting | Yes | Yes | Low |
Managed bot hosting gives you a panel with a console, file manager, environment variables and automatic restarts, without maintaining a server. Kerit Cloud’s Telegram bot hosting runs persistent processes on AMD EPYC with NVMe storage, from a free plan up, with under 40 ms latency to the Telegram API from the Virginia edge.
Step 1: Create the bot and get a token
Open a chat with @BotFather, send /newbot, choose a name and a username ending in bot, and copy the token it gives you. Treat the token like a password — anyone with it controls your bot. If it ever leaks, send /revoke to BotFather to issue a new one.
Step 2: Prepare the project
Make the project deployable:
- Declare dependencies in
requirements.txt(Python) orpackage.json(Node.js). - Read the token from the environment, never from code.
- Log to standard output so you can see what happens in the host’s console.
A minimal aiogram 3 bot:
import asyncio
import logging
import os
from aiogram import Bot, Dispatcher
from aiogram.filters import CommandStart
from aiogram.types import Message
dp = Dispatcher()
@dp.message(CommandStart())
async def start(message: Message):
await message.answer("Hello! I'm online 24/7.")
async def main():
logging.basicConfig(level=logging.INFO)
bot = Bot(os.environ["BOT_TOKEN"])
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
With requirements.txt:
aiogram>=3.4,<4
A full walkthrough is in deploying an aiogram 3 bot. Node.js developers can follow building a grammY bot or hosting a Telegraf bot.
Step 3: Create a server and upload
On Kerit Cloud:
- Create a server on the free plan or a paid Telegram plan, choosing Python (3.9–3.12), Node.js (16–22) or Java (11, 17, 21).
- Upload your code with the file manager or SFTP, or — on paid plans — link a git repository so every push redeploys automatically.
- Add
BOT_TOKEN(and any API keys) as environment variables. They’re stored encrypted and kept out of logs. - Set the start command, for example
python -u bot.pyornode bot.js.
Step 4: Start and verify
Start the server and watch the console. Dependencies install first, then your bot starts polling. Send /start to your bot in Telegram — the reply should arrive almost instantly. If the process crashes, the watchdog restarts it within seconds and the error stays in the console.
Warning: Only one process can poll a bot at a time. If your bot is still running on your PC, Telegram returns a
409 Conflict: terminated by other getUpdates requesterror. Stop the local copy.
A production checklist
- Handle errors per update. One malformed message shouldn’t crash the bot. aiogram, grammY and Telegraf all offer global error handlers — use them.
- Respect rate limits. Telegram limits how fast bots can send, especially to groups and when broadcasting. See Telegram Bot API limits.
- Store state in a database. Conversation state, user settings and subscriptions should survive restarts. See storing Telegram bot state.
- Secure admin commands. Check the sender’s user ID, not their username, before running privileged actions.
- Shut down cleanly. Stop polling and close database connections on SIGTERM so restarts don’t lose updates.
- Back up. Paid plans include daily backups; export anything critical regularly too.
How many resources does a Telegram bot need?
Telegram bots are usually light. A typical aiogram bot using long polling idles around 70 MB, comfortably inside the free plan’s 256 MB. Bots grow with concurrency, media processing and in-memory caches. The Starter plan (1 GB RAM) suits growing bots with a database; Pro (2 GB) adds PostgreSQL and priority support; Ultra (4 GB) supports several bots per server, Redis and region choice. Choosing a Telegram bot plan goes through each tier.
Troubleshooting
The bot doesn’t answer at all. Check the console for errors and confirm the token variable is set. If you previously set a webhook, polling won’t receive updates until you delete it — call deleteWebhook or use your library’s drop_pending_updates option.
409 Conflict. Two processes are polling, or a webhook is active while you poll.
It stops responding after a while. Look for an unhandled exception in a handler, a blocking call freezing the event loop, or the process running out of memory. Debugging a Telegram bot that stops responding covers each case.
Userbot asks to log in again after a restart. The session file isn’t persisted, or it’s being recreated. See Telethon and Pyrogram session files.
Summary
A Telegram bot receives updates through long polling or webhooks, and either way needs a process that never sleeps, restarts automatically and keeps its files. Get a token from BotFather, read it from an environment variable, declare dependencies, and deploy to a host built for long-running processes. Then add error handling, rate-limit awareness and a database, and the bot will run for months without attention.