How to Host a Telegram Bot
On this page
A Telegram bot only answers while its code is running. Build one on your laptop and it goes quiet the moment the laptop sleeps — so sooner or later every bot needs a home that stays on.
This guide covers the whole path: creating the bot with BotFather, choosing between polling and webhooks, a working example in Python and in JavaScript, the limits and rules Telegram sets, and how to keep the bot online 24/7.
Step 1: Create the bot with BotFather
- In Telegram, open @BotFather and send
/newbot. - Give the bot a display name, then a username: 5 to 32 characters, Latin letters, digits and underscores, ending in
bot— for examplemy_shop_helper_bot. - BotFather replies with the token, which looks like
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11. Anyone who has it controls your bot, so keep it out of your code and never share it. If it leaks, send/tokento BotFather to get a new one.
Two more BotFather commands worth knowing: /setcommands adds the command list users see when they type /, and /setprivacy controls what the bot sees in groups. By default privacy mode is on, so in a group the bot only receives commands meant for it and replies to its own messages — unless you make it an admin.
Polling or webhooks?
A bot gets its messages from Telegram in one of two ways — never both at the same time:
| Long polling | Webhook | |
|---|---|---|
| How it works | The bot keeps asking Telegram for new messages over one open connection | Telegram sends each update to your HTTPS address |
| Needs | Only outgoing internet access | A domain, a valid certificate and port 443, 80, 88 or 8443 |
| Best for | Almost every bot, and the easiest to host | Very busy bots, or serverless platforms |
Start with polling. It needs no domain, no certificate and no open port, and every library supports it. If a webhook was ever set on the token, call deleteWebhook first — polling does not work while a webhook is active.
Polling bots run on HytHost bot hosting with no domain or open port to set up — Python or Node.js from €0.89/mo.
See bot hosting plansStep 2a: A bot in Python (python-telegram-bot)
python-telegram-bot 22 needs Python 3.10 or newer. Install it with pip install python-telegram-bot and create bot.py:
import os
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text("Hi! Send me a message and I will echo it.")
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(update.message.text)
def main() -> None:
application = Application.builder().token(os.environ["TELEGRAM_TOKEN"]).build()
application.add_handler(CommandHandler("start", start))
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
application.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
main()
aiogram 3 is the other popular choice in Python, also on Python 3.10 or newer.
Step 2b: A bot in JavaScript (grammY)
grammY is the actively maintained Telegram framework for Node.js. Run npm install grammy and create bot.js:
const { Bot } = require("grammy");
const bot = new Bot(process.env.TELEGRAM_TOKEN);
bot.command("start", (ctx) => ctx.reply("Welcome! Up and running."));
bot.on("message:text", (ctx) => ctx.reply(ctx.message.text));
process.once("SIGINT", () => bot.stop());
process.once("SIGTERM", () => bot.stop());
bot.start();
Older tutorials use Telegraf, which has had no release since February 2024; for a new bot, grammY is the safer pick.
Telegram's limits and rules for bots
Limits from Telegram's bot FAQ:
- About one message per second in a single chat, 20 messages per minute in a group, and about 30 messages per second overall.
- Files: the bot can send up to 50 MB and download up to 20 MB.
- Only one copy of the bot may poll at a time. A second one gets Conflict: terminated by other getUpdates request — use a separate token for testing.
Rules: Telegram's terms for bot developers forbid spam and unsolicited messages and getting around rate limits. A bot needs a privacy policy (Telegram's standard one applies if you do not write your own) and must delete a user's data when asked. Automating a personal account instead of a bot — a so-called userbot — is a different thing entirely, and Telegram bans accounts used for flooding or spam.
Telegram bot hosting on HytHost
Our bot hosting plans run Telegram bots as well as Discord bots:
- Pick a plan and the runtime — Python for python-telegram-bot or aiogram, Node.js for grammY. Choose Python 3.10 or newer, or a current Node.js, in the Startup tab.
- Upload your code with the file manager or SFTP, together with
requirements.txtorpackage.json. - Put the token in a
.envfile or an environment variable, not in the code. - Start it. With polling the bot needs no domain or open port; the panel restarts it if it crashes.
What our rules allow: bots built on the official Bot API with a BotFather token. Not allowed: userbots that automate a personal account, unsolicited mass messages, scraping users or groups, and bots that download and pass on media without the rights to it. A bot that breaks these rules is suspended.
Plans include a MySQL database and backups. Making a Discord bot as well? See how to make a Discord bot.
Keep your Telegram bot online 24/7 without your PC: Python or Node.js bot hosting from €0.89/mo, restarts included.
See bot hosting plansFrequently asked questions
You can run it on your own computer for free, but it goes offline whenever the computer sleeps or restarts. Free cloud tiers often pause idle apps or cap their usage. For a bot that stays online, a small paid host is the reliable option.
Polling for almost every bot: it needs no domain, certificate or open port. Webhooks suit very busy bots or serverless platforms, and need HTTPS on port 443, 80, 88 or 8443. A token cannot use both at once.
Send /token to @BotFather and pick the bot to get a new token, then update it wherever the bot runs. Keep the token in an environment variable or a .env file, never in code you share.
Two copies of the bot are polling with the same token, for example one on your PC and one on the server. Stop one of them, and use a separate bot and token for testing.
Very little. A typical Python or Node.js bot that answers commands usually runs fine on 512 MB; bots that process images or hold large data in memory need more.
Your Telegram bot, online 24/7
HytHost bot hosting runs your Python or Node.js Telegram bot with automatic restarts, a MySQL database and backups — from €0.89/mo.
Live chat 8 AM – 11 PM (Chișinău time) · tickets answered during business hoursWas this guide helpful?