Deploy a Telegram Bot
You can deploy a Telegram bot built with Telegraf, grammY, aiogram, or Telebot on App Platform. The bot can receive messages through long polling or webhooks.
Configure the Build Copy link
App Platform builds your app from the repository root, or from the directory you set in the Project Directory Path field. You can choose the runtime version (Node.js, Python, or Go) when creating the app.
Under Advanced Settings, check the build and start commands. Make sure your framework and all other dependencies are listed in the dependencies file. If your project builds or starts differently, update the commands.
Node.js (Telegraf, grammY) Copy link
- Dependencies file:
package.json - Build command:
npm install - Start command:
npm start
The scripts section of package.json must include a start script that launches the bot. If your project uses TypeScript, add compilation to the build command and point the start script to the compiled file.
Python (aiogram) Copy link
- Dependencies file:
requirements.txt - Build command:
pip install --upgrade -r requirements.txt - Start command:
python3 main.py
Choose a Python version that is compatible with your version of aiogram.
Go (Telebot) Copy link
- Dependencies file:
go.mod - Build command:
go build -o main . - Start command:
./main
Dependencies are downloaded through Go Modules. The build command creates an executable named main, so the start command must use the same name.
Set Environment Variables Copy link
When you select a framework, App Platform adds a BOT_TOKEN variable by default. Set it to the bot token you got from @BotFather.
If your code reads the token from a variable with a different name, create that variable manually in the Variables block and set its value.
Deploy the App Copy link
Click Deploy to start. You can follow the build and startup progress on the Deploy tab.
Once the bot is running, send it a command that has a handler in your code and check that it replies in Telegram.
Set Up Webhooks Copy link
Webhooks are an alternative to long polling. You can use the free technical domain from App Platform or your own domain attached to the app.
If your bot uses long polling, it requests new messages from Telegram on its own, so you don't need a webhook or a domain. Skip this section.
The domain is only available after the first deployment, so the first deploy will fail with an empty domain variable. Once it fails, you add the domain and deploy again.
- Make your project read the webhook domain from an environment variable, for example
WEBHOOK_DOMAIN. You can also pass a secret for request verification throughWEBHOOK_SECRET. - When creating the app, add both variables in the dashboard. Set
WEBHOOK_SECRETto a random value and leaveWEBHOOK_DOMAINempty. - Click Deploy. The deployment will fail because the domain is empty. That's expected.
- Open the Dashboard tab and copy the technical domain. To use your own domain, add it to the app first.
- Go to the Settings tab, open the deployment settings, and set
WEBHOOK_DOMAINto your app's domain. - Save your changes. App Platform redeploys the app, and with the domain set, Telegraf registers the webhook and starts the bot.
Troubleshooting Copy link
Deployment Fails Copy link
Check the deploy log first. Then check the following for your runtime:
- Node.js: All dependencies are listed in
package.json, and thestartscript points to an existing file. If your project needs a build step, make sure it runs before the app starts. - Python: All dependencies are listed in
requirements.txt, the start command points to an existing file, and your Python version is compatible with your version of aiogram. - Go: All dependencies are listed in
go.mod, the build directory contains amainpackage with amain()function, and the executable created by the build has the same name as in the start command.
Bot Doesn't Respond Copy link
Check that:
- The token is stored in a variable with the same name your code uses.
- Your code has a handler for the command you sent.
If you use long polling, make sure no other instance of the bot is running with the same token, for example on your local machine. Telegram doesn't allow long polling and webhooks at the same time.
If you use webhooks, check the WEBHOOK_DOMAIN value and your secret. Also make sure the app listens on 0.0.0.0 rather than 127.0.0.1, otherwise external connections won't reach it. If the domain is still empty after the first failed deploy, set it and redeploy, as described in Set Up Webhooks.