# aiogram bot hosting: how to deploy an aiogram 3 bot

> An aiogram 3 bot needs one process that never stops, the token in an environment variable, state kept outside memory and a clean exit on SIGTERM. On Livops you push a repository with bot.py and requirements.txt, and it runs for 19 credits a month (19,000 so'm), polling or webhook.

Source: https://livops.dev/en/guides/aiogram-bot-hosting

By Livops team, the people who build and run Livops. Updated 19 November 2026.

aiogram is the asyncio framework most Python Telegram bots are written with, and an aiogram 3 bot is a long-running program: it either asks Telegram for updates in a loop or listens for Telegram's HTTPS requests. Hosting it well comes down to four things — one process that stays up, the token kept out of the code, state that survives a restart, and an exit that does not drop a reply halfway. This page covers each for aiogram 3.32, the current release, and then the exact files Livops reads to run one.

## What does an aiogram bot need in production?

### One process, polling or webhook — never both

Telegram has two ways of delivering updates and they are mutually exclusive[6]; aiogram says the same: with a webhook set, long polling cannot run[2]. Pick one per bot. With polling, `getUpdates` stops working while a webhook is set[6], and aiogram's `start_polling` does not remove a webhook for you[8]: a bot moved from a webhook host has to call `deleteWebhook` once, or it receives nothing.

### The right aiogram and the right Python

aiogram 3.32 was released on 15 November 2026 and needs Python 3.11 or newer, below 3.16[5]. aiogram 2 and 3 share a package name and little else: code that imports `executor` is aiogram 2 and will not start on 3. Pin the major version you wrote for:

```text
aiogram>=3.32,<4
```

### The token from the environment

The token BotFather gave you is the bot. Read it from an environment variable and keep it out of the repository, `.env` files included.

### A clean exit on SIGTERM

A host stops a process with SIGTERM. `start_polling` and `run_polling` handle SIGINT and SIGTERM themselves while `handle_signals` is `True`, the default[8]. By default the dispatcher does not wait for handlers still running; pass `tasks_shutdown_timeout` and it stops fetching, waits that long for them, then cancels the rest[1]. Keep the timeout shorter than the host's own stop window.

### State that survives a restart

aiogram's default FSM storage, `MemoryStorage`, keeps everything in a dict and loses it on every restart; the docs advise against it in production[3]. `RedisStorage.from_url()` takes a Redis URL and needs the `redis` package installed[3].

## A production aiogram bot, polling

```python
import asyncio
import os

from aiogram import Bot, Dispatcher
from aiogram.filters import CommandStart
from aiogram.fsm.storage.redis import RedisStorage
from aiogram.types import Message

dp = Dispatcher(storage=RedisStorage.from_url(os.environ["REDIS_URL"]))


@dp.message(CommandStart())
async def start(message: Message) -> None:
    await message.answer("Hello!")


async def main() -> None:
    bot = Bot(token=os.environ["BOT_TOKEN"])
    # Wait up to 5 s for running handlers when SIGTERM arrives.
    await dp.start_polling(bot, tasks_shutdown_timeout=5)


if __name__ == "__main__":
    asyncio.run(main())
```

`requirements.txt`:

```text
aiogram>=3.32,<4
redis
```

## The same bot on a webhook

For a webhook, aiogram ships an aiohttp handler. `SimpleRequestHandler` compares the `X-Telegram-Bot-Api-Secret-Token` header with `secret_token` and answers 401 when they differ[4] — but only when a secret is set, so always set one. It answers Telegram at once and runs the handler in the background by default (`handle_in_background`)[2].

```python
import os

from aiohttp import web
from aiogram import Bot, Dispatcher
from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_application

bot = Bot(token=os.environ["BOT_TOKEN"])
dp = Dispatcher()
# ... handlers as above ...

app = web.Application()
SimpleRequestHandler(dp, bot, secret_token=os.environ["WEBHOOK_SECRET"]).register(
    app, path=os.environ["WEBHOOK_PATH"]
)
setup_application(app, dp, bot=bot)
web.run_app(app, host="0.0.0.0", port=int(os.environ["PORT"]), shutdown_timeout=20)
```

Two differences from aiogram's own example. Its server binds `127.0.0.1`, because it expects a reverse proxy on the same machine[2]; in a container the platform reaches, bind `0.0.0.0`. And its `on_startup` calls `bot.set_webhook()`[2]; leave that out on a platform that sets the webhook for you. aiohttp's `run_app` waits up to `shutdown_timeout`, 60 seconds by default[7], which is longer than most hosts wait — hence 20 above.

## Deploy an aiogram bot on Livops

1. Push a repository with `bot.py` and `requirements.txt`, or upload the folder as a `.zip`. In the cabinet, create a project from it. There is also a ready **aiogram 3 bot + Redis** template.
2. Under **Settings → Variables**, add `BOT_TOKEN` with the token and mark it as a secret: its value is never shown again.
3. For FSM state, add a Redis database under **Databases**; `REDIS_URL` is written into the bot's variables by itself.
4. Deploy. The log shows the install and the start.

Livops sees aiogram in `requirements.txt` (or in your imports, when there is no requirements file) and makes the project a **Telegram bot (Python)**. It installs into a virtualenv and starts `bot.py`; with no `bot.py` it looks for `main.py`, `app.py`, `run.py`, `src/<package>/__main__.py` or a file with `if __name__ == "__main__"`. To set it yourself, put `livops.json` in the repository root:

```json
{
  "kind": "bot",
  "start": ".venv/bin/python bot.py"
}
```

A `Procfile` with `worker: .venv/bin/python bot.py` does the same. A `.python-version` file picks the Python version.

**Polling** is the default and needs nothing else: no port, no domain. For a **webhook**, open the project's **Settings → Connection to Telegram**, choose Webhook and press **Save and redeploy**. If your code already uses `SimpleRequestHandler`, the new-project wizard picks webhook mode on its own. The platform generates `WEBHOOK_SECRET`, tells Telegram the address with that secret once the bot answers, and refuses requests to the path that do not carry it. Your code listens on `PORT`, receives on `WEBHOOK_PATH` (`/webhook` unless you change it) and checks `WEBHOOK_SECRET` — exactly the webhook example above. In webhook mode the token must be in `BOT_TOKEN`.

What happens after that:

- **On a new push**, a polling bot is stopped first — SIGTERM, then ten seconds — and the new version starts, so two copies never poll with one token. A webhook bot's new copy must answer on `PORT` within a minute; it takes the updates before the old one is stopped.
- **If the bot exits in its first 30 seconds**, the deploy is marked failed and the log shows its last lines. If the build fails, the running version is left alone.
- **If it crashes later**, it is started again. Ten crashes inside 15 minutes and it is stopped, and you are notified with the last lines it printed — in Telegram, if your account is linked.
- **Files** written to `/app/data` (the `DATA_DIR` variable) survive restarts and deploys; `/tmp` and the code folder do not. An `aiosqlite` file belongs there. For orders or payments, use PostgreSQL, which is backed up.
- **The clock is UTC.** For schedules in Tashkent time, add `TZ=Asia/Tashkent` under **Variables**.

A bot costs **19 credits a month (19,000 so'm)**, polling or webhook. One credit is 1,000 so'm; see [Pricing](https://livops.dev/en/docs/pricing).

## Livops or a VPS for an aiogram bot?

A VPS gives you root and room for several bots on one machine, which is the cheaper path once you have many. In exchange you install Python, write a systemd unit that restarts the bot, deploy by hand, and keep the system updated. On Livops a `git push` is the deploy and restarts are the platform's job, but you get no root: a bot that needs system packages of its own is better on a VPS or in its own `Dockerfile`.

## Questions

**Does Livops run aiogram 2 bots?**

Yes, as long as the version is pinned. If requirements.txt says aiogram with no version and the code imports executor, Livops installs aiogram below 3 so the old code still starts. New bots should be written for aiogram 3.

**Which file does Livops start?**

bot.py by default. If there is none, it looks for main.py, app.py, run.py, src/<package>/__main__.py or a file with if __name__ == "__main__". You can name the command yourself in livops.json or in Settings.

**Polling or webhook for an aiogram bot?**

Polling unless you have a reason. It needs no address and no port. If your code uses SimpleRequestHandler, the wizard picks webhook mode for you, and the platform tells Telegram the address; your code must not call set_webhook.

**Where should an aiogram bot keep FSM state?**

Not in MemoryStorage, which is lost on every restart and deploy. Add a Redis database to the project and pass REDIS_URL to RedisStorage.from_url. A SQLite file belongs in /app/data, the DATA_DIR variable.

**What happens when I push a new version?**

A polling bot is stopped first, with SIGTERM and ten seconds to finish, and the new one starts after it, so two copies never poll at once. Messages sent in between wait at Telegram. A webhook bot's new copy starts and takes updates before the old one is stopped.

**How much does it cost?**

19 credits a month, 19,000 so'm at 1,000 so'm a credit, the same for polling and webhook. There is no free tier for bots; the first bot on an account that has not paid runs for 15 minutes on a zero balance.

## Sources

1. [aiogram — Long-polling](https://docs.aiogram.dev/en/latest/dispatcher/long_polling.html). Checked 19 November 2026.
2. [aiogram — Webhook](https://docs.aiogram.dev/en/latest/dispatcher/webhook.html). Checked 19 November 2026.
3. [aiogram — FSM storages](https://docs.aiogram.dev/en/latest/dispatcher/finite_state_machine/storages.html). Checked 19 November 2026.
4. [aiogram source — aiogram/webhook/aiohttp_server.py](https://raw.githubusercontent.com/aiogram/aiogram/dev-3.x/aiogram/webhook/aiohttp_server.py). Checked 19 November 2026.
5. [aiogram on PyPI](https://pypi.org/project/aiogram/). Checked 19 November 2026.
6. [Telegram Bot API — Getting updates](https://core.telegram.org/bots/api). Checked 19 November 2026.
7. [aiohttp — Server reference (run_app)](https://docs.aiohttp.org/en/stable/web_reference.html). Checked 19 November 2026.
8. [aiogram source — aiogram/dispatcher/dispatcher.py](https://raw.githubusercontent.com/aiogram/aiogram/dev-3.x/aiogram/dispatcher/dispatcher.py). Checked 19 November 2026.
