Bots
How to host a Telegram bot 24/7
Telegram bots are easy to build and just need somewhere to run all day.
Create the bot
Open BotFather in Telegram, send /newbot, follow the steps and copy the token. Keep it private.
Polling or webhook
- Long polling: your bot asks Telegram for updates. It's simple and works anywhere. Use this to start.
- Webhook: Telegram sends updates to a web address of yours. It needs HTTPS and a public port.
Deploy
- Upload your bot's files.
- Install dependencies (npm install or pip install -r requirements.txt).
- Set the start command, such as node bot.js or python bot.py.
- Add the token as an environment variable and start the bot.
Common errors
- "409 Conflict: terminated by other getUpdates request": two copies of the bot are running. Stop the other one, including any on your PC.
- "401 Unauthorized": the token is wrong or was revoked.
- "Forbidden: bot was blocked by the user": the user blocked your bot. It can't message them.
- "Too Many Requests: retry after": you are sending too fast. Slow down and wait.
- Bot works then stops: check the logs for errors and enable auto-restart.