---
title: "Deploy a Telegram Bot | Hostman Docs"
description: "Deploy a Telegram bot built with Telegraf, grammY, aiogram, or Telebot on App Platform. Set up the build, variables, and webhooks or long polling."
---

> For the complete documentation index for AI agents, see [llms.txt](https://hostman.com/llms.txt).

You can deploy a Telegram bot built with [Telegraf](https://telegraf.js.org/), [grammY](https://grammy.dev/), [aiogram](https://docs.aiogram.dev/), or [Telebot](https://github.com/tucnak/telebot) on App Platform. The bot can receive messages through long polling or webhooks.

## Configure the Build

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)

-   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)

-   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)

-   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

When you select a framework, App Platform adds a `BOT_TOKEN` variable by default. Set it to the bot token you got from [@BotFather](https://t.me/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

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

Webhooks are an alternative to long polling. You can use the free technical domain from App Platform or [your own domain](https://hostman.com/docs/app-platform/domains/) 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.

1.  Make your project read the webhook domain from an environment variable, for example `WEBHOOK_DOMAIN`. You can also pass a secret for request verification through `WEBHOOK_SECRET`.
2.  When creating the app, add both variables in the dashboard. Set `WEBHOOK_SECRET` to a random value and leave `WEBHOOK_DOMAIN` empty.
3.  Click **Deploy**. The deployment will fail because the domain is empty. That's expected.
4.  Open the **Dashboard** tab and copy the technical domain. To use your own domain, [add it to the app](https://hostman.com/docs/app-platform/domains/#add-a-custom-domain) first.
5.  Go to the **Settings** tab, open the deployment settings, and set `WEBHOOK_DOMAIN` to your app's domain.
6.  Save your changes. App Platform redeploys the app, and with the domain set, Telegraf registers the webhook and starts the bot.

## Troubleshooting

### Deployment Fails

Check the deploy log first. Then check the following for your runtime:

-   **Node.js**: All dependencies are listed in `package.json`, and the `start` script 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 a `main` package with a `main()` function, and the executable created by the build has the same name as in the start command.

### Bot Doesn't Respond

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](https://hostman.com/docs/app-platform/backend-apps/telegram-bots/#set-up-webhooks).
