Telegram bot in Python or Node.js
How to run a bot on aiogram, python-telegram-bot, telegraf or grammY — with long polling or a webhook.
A bot is a regular app from Git or an archive. There are two ways to run it, and the price depends on the choice.
| Way | When it fits | Price |
|---|---|---|
| Long polling (background process) | The bot asks Telegram for new messages itself. Simplest, works everywhere | The full app plan: the bot does not sleep |
| Webhook | Telegram sends messages to the bot's address | You can enable sleep: with no messages you pay 25% of the plan |
Bot with long polling
- “New resource” → “App”.
- Enter the repository link and tick “Background process or Telegram bot, no website”. No port needed: the deploy checks that the process is running.
- In “Environment variables” add the token from @BotFather:
BOT_TOKEN=123456:ABC...
- Plan Nano or Micro: an aiogram bot needs 256–512 MB.
How the platform knows what to run:
- a
Procfilewith the lineworker: python bot.py— that line runs; - Python without a Procfile — it looks for
app.py, thenmain.py, thenbot.py; - Node.js —
npm startfrompackage.json.
Read the token from the variable, not from the code:
import os
from aiogram import Bot
bot = Bot(token=os.environ["BOT_TOKEN"])
Bot with a webhook
Create a regular app without the "background process" tick. The platform passes the port in the PORT variable — listen on it. The app address appears in the resource card; set the webhook like this:
https://api.telegram.org/bot<token>/setWebhook?url=https://<app address>/webhook
In the “Settings” tab you can enable sleep: the first message after a quiet period wakes the bot in a few seconds.
Log and restarts
The “Log” tab streams the bot's output. If the bot crashes, the resource restarts by itself and the event appears in the feed. To learn about crashes right away, add a notification channel or an account webhook for the “Resource crashed” event.