Telegram bots are some of the easiest bots to host: they don't need a permanent connection like Discord's gateway, and with long polling they don't even need a domain or open port. This guide creates a bot, writes a minimal version in Python and Node.js, and puts it on a server that runs it 24/7.
1. Create the bot with BotFather
Open Telegram, message @BotFather and send /newbot. Choose a display name and a username ending in "bot". BotFather replies with a token that looks like 123456789:AA.... Treat it like a password: anyone with it controls your bot.
2. Polling or webhooks?
Your bot can receive messages in two ways:
- Long polling: the bot repeatedly asks Telegram for new updates. It works from any server, with no domain or certificate. Best for most bots.
- Webhooks: Telegram sends each update to your HTTPS URL. This needs a public endpoint on port 443, 80, 88 or 8443 with a valid certificate. It's useful at very high volume or when the bot is part of a web app.
This guide uses long polling, which works on any Telegram bot hosting plan.
3a. A minimal bot in Python
Using python-telegram-bot, put this in requirements.txt:
python-telegram-bot>=21and this in bot.py:
import os
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Hello! I'm online 24/7.")
def main():
app = Application.builder().token(os.environ["TELEGRAM_TOKEN"]).build()
app.add_handler(CommandHandler("start", start))
app.run_polling()
if __name__ == "__main__":
main()3b. A minimal bot in Node.js
Using grammY, install it with npm install grammy and create index.js:
const { Bot } = require('grammy');
const bot = new Bot(process.env.TELEGRAM_TOKEN);
bot.command('start', (ctx) => ctx.reply("Hello! I'm online 24/7."));
bot.catch((err) => console.error('Bot error:', err));
bot.start();4. Keep the token out of your code
Both examples read the token from the TELEGRAM_TOKEN environment variable. On Zettako, set it as a startup variable in the panel. Elsewhere, use a .env file that you never commit to Git.
5. Upload and start
- Order a Telegram bot hosting plan and pick Python or Node.js.
- Upload your files through the file manager or SFTP, without
venvornode_modules. - Set the startup file to
bot.pyorindex.jsand addTELEGRAM_TOKEN. - Press start, then send
/startto your bot.
Troubleshooting
- 409 Conflict: terminated by other getUpdates request: another copy of the bot is running with the same token, probably on your own computer. Stop it. Only one poller can run per token.
- No updates at all: if you used webhooks before, polling won't receive anything until you remove the webhook with
deleteWebhook. - 401 Unauthorized: the token is wrong or was revoked with BotFather.
- Bot doesn't see group messages: bots in groups only see commands and replies by default. Turn off privacy mode with BotFather's
/setprivacyif you need every message.
Please use your bot responsibly: unsolicited mass messaging breaks Telegram's rules and our acceptable use policy.