// DevOps

Self-Hosted Telegram Bot API: Run Your Own Server with Docker (2 GB Files, HTTP Webhooks)

Published on 2026-05-29

Local Telegram Bot API allows developers to run their own API server, providing significant advantages for handling large files, performance, and configuration flexibility. However, to understand the need for a local server, it’s important to consider the limitations of the standard Telegram Bot API that works via an HTTPS interface. In this article we’ll review the benefits of the Local Bot API, the limitations of the standard approach, and steps to set up a local server via Docker, including registering a bot to use with it.


🚀 Main advantages of the Local Bot API

1. Increased file handling limits

For developers whose bots actively work with media, a local API server opens new possibilities:

  • Upload files up to 2 GB:
    Unlike the standard Bot API, which limits uploaded file size to 50 MB, the local server allows working with files up to 2000 MB (2 GB). This is ideal for bots that process videos, audio, or other large media files.

  • Download files without restrictions:
    The local API allows downloading files from Telegram servers without size restrictions (up to 2000 MB), whereas the standard API limits downloads to 20 MB.

  • Use of local path for uploads:
    The local API server supports specifying a local path or the file:// URI scheme for uploads, which eliminates the need to transmit files via HTTP requests.


2. Reduced network latency

A local API server can significantly improve performance:

  • Latency reduction:
    Requests from your bot are first sent to your local API server and then forwarded to Telegram servers.
    If your bot and API server are in the same network or geographically close, this reduces network latency, enabling faster request handling.

3. Flexibility and increased limits for Webhook

Using a local API server expands webhook configuration options:

  • HTTP support:
    Unlike the standard Bot API, which requires HTTPS, the local server allows using HTTP for webhooks, simplifying setup in some scenarios.

  • Any IP and port:
    You can configure webhooks on any local IP address and any port, providing flexibility in server configuration.

  • Increased number of connections:
    The local API server supports up to 100,000 concurrent webhook connections, which far exceeds the limits of the standard API (restricted by HTTPS and ports 443, 80, 88, 8443).


4. Faster file access

The getFile method returns an absolute local path (file_path), which allows avoiding additional download requests if files are already available on your server.


🛑 Limitations of the standard Telegram Bot API

ParameterLimitNote
Global limit (overall)≤ 30 messages per secondMaximum send rate from one bot to all chats.
Single chat (private)≤ 1 message per secondPer user.
Group/channel≤ 20 messages per minutePer chat.
Sending files≤ 50 MBVia the standard API.
Receiving files≤ 20 MBWhen downloading from Telegram servers.
Message length≤ 4096 characters
Media caption≤ 1024 characters
Inline buttons≤ 100
Commands≤ 100Configured via @BotFather.
WebhooksOnly HTTPS and limited ports443, 80, 88, 8443

🛠 Setting up Local Bot API via Docker

1. Preparation

Before starting, make sure you have Docker and Docker Compose installed, and you have an API ID and API Hash obtained at my.telegram.org.

Create a file .env:

env
TELEGRAM_API_ID=ваш_api_id
TELEGRAM_API_HASH=ваш_api_hash

2. Docker Compose configuration

File docker-compose.yml:

yaml
version: "3.8"
services:
  telegram-bot-api:
    build: ./telegram-bot-api-builder
    container_name: telegram-local-api
    restart: unless-stopped
    environment:
      TELEGRAM_API_ID: ${TELEGRAM_API_ID}
      TELEGRAM_API_HASH: ${TELEGRAM_API_HASH}
    ports:
      - "8081:8081"
    volumes:
      - tgdata:/var/lib/telegram-bot-api
    command:
      - --api-id=${TELEGRAM_API_ID}
      - --api-hash=${TELEGRAM_API_HASH}
      - --http-port=8081
      - --dir=/var/lib/telegram-bot-api

volumes:
  tgdata:

3. Dockerfile

File telegram-bot-api-builder/Dockerfile:

dockerfile
# ---------- Stage 1: Build ----------
FROM ubuntu:24.04 AS builder

ARG DEBIAN_FRONTEND=noninteractive
# Позволяет зафиксировать конкретный коммит/тег при сборке:
# пример: --build-arg TELEGRAM_BOT_API_REF=v7.2
ARG TELEGRAM_BOT_API_REF=master

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
      build-essential g++ cmake git \
      libssl-dev zlib1g-dev ca-certificates && \
    rm -rf /var/lib/apt/lists/*

# Клонируем и фиксируемся на нужной ревизии
WORKDIR /src
RUN git clone https://github.com/tdlib/telegram-bot-api.git . --depth 1 --branch ${TELEGRAM_BOT_API_REF}

# Сборка
RUN mkdir -p build && cd build && \
    cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. && \
    cmake --build . --target telegram-bot-api -j"$(nproc)"

# Сжимаем бинарник (уменьшаем размер)
RUN strip /src/build/telegram-bot-api || true


# ---------- Stage 2: Runtime ----------
FROM ubuntu:24.04

ARG DEBIAN_FRONTEND=noninteractive

# Минимальные зависимости рантайма:
# libssl3 для Ubuntu 24.04, zlib, сертификаты для исходящих запросов
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
      libssl3 zlib1g ca-certificates curl && \
    rm -rf /var/lib/apt/lists/*

# Каталог данных + системный пользователь
RUN groupadd -r telegram-bot-api && \
    useradd  -r -g telegram-bot-api -d /var/lib/telegram-bot-api -s /sbin/nologin telegram-bot-api && \
    mkdir -p /var/lib/telegram-bot-api && \
    chown -R telegram-bot-api:telegram-bot-api /var/lib/telegram-bot-api

# Копируем бинарник
COPY --from=builder /src/build/telegram-bot-api /usr/local/bin/telegram-bot-api

# Порт по умолчанию (меняйте в docker-compose командой --http-port)
EXPOSE 8081

# Healthcheck: простой HTTP-пинг локального порта
ENV HEALTH_PORT=8081
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
  CMD curl -fsS "http://127.0.0.1:${HEALTH_PORT}/" >/dev/null || exit 1

USER telegram-bot-api
WORKDIR /var/lib/telegram-bot-api

# Параметры (api-id, api-hash, порты, директории) передаются через docker-compose:
#   command: ["--api-id=...", "--api-hash=...", "--http-port=8081", "--dir=/var/lib/telegram-bot-api"]
ENTRYPOINT ["/usr/local/bin/telegram-bot-api"]

Features of this version:

  • Base is Ubuntu 24.04 with libssl3.
  • Parallel build and strip of the binary to reduce size.
  • HEALTHCHECK for container monitoring.
  • Secure non-privileged user.
  • Ability to set build tag TELEGRAM_BOT_API_REF for reproducibility.

4. Starting the server

bash
docker-compose up -d

After start, the server will be available at:

http://localhost:8081

5. Check and register the bot

bash
curl http://localhost:8081/bot<YOUR_TOKEN>/getMe

If you see a JSON response with the bot’s name — everything works.


6. Usage in code

Python (python-telegram-bot)

python
from telegram.ext import Updater
updater = Updater(token='YOUR_TOKEN', base_url='http://localhost:8081')

Node.js (node-telegram-bot-api)

javascript
const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot('YOUR_TOKEN', { baseUrl: 'http://localhost:8081' });

7. Webhook setup

bash
curl -X POST \
  http://localhost:8081/bot<YOUR_TOKEN>/setWebhook \
  -d '{"url": "http://your_server_ip:8081/bot<YOUR_TOKEN>"}'

💡 Summary

Local Telegram Bot API is a powerful solution for:

  • working with large files (up to 2 GB);
  • reducing latency;
  • flexible webhook configuration;
  • high-load systems.

The standard API is suitable for:

  • small projects;
  • working with files up to 50 MB;
  • typical HTTPS webhooks.

Setting up via Docker ensures reproducibility, easy updates, and isolation security. The Dockerfile is an optimal option for stable and easy building of the Telegram Bot API in production.


Frequently Asked Questions

What is the local Telegram Bot API server?
The local Telegram Bot API server is a self-hosted version of Telegram’s Bot API that runs on your own infrastructure. Unlike the standard API at api.telegram.org, it removes file size limits (up to 2 GB), allows HTTP webhooks on any port, and supports up to 100,000 concurrent webhook connections.
What is the maximum file size supported by the local Telegram Bot API?
The local Telegram Bot API server supports uploading and downloading files up to 2 GB. The standard Telegram Bot API limits uploads to 50 MB and downloads to 20 MB.
Does the local Telegram Bot API require HTTPS?
No. The standard API requires HTTPS and only accepts webhooks on ports 443, 80, 88, and 8443. The local server supports plain HTTP and accepts webhooks on any IP address and any port.
How do I run the local Telegram Bot API server with Docker?
You need Docker and a Telegram API ID and API Hash from my.telegram.org. Create a docker-compose.yml and a Dockerfile that builds the official telegram-bot-api binary, then run docker-compose up -d. The server starts on http://localhost:8081 by default.
What is the difference between the standard and local Telegram Bot API?
The standard API is a shared Telegram service at api.telegram.org: 50 MB upload limit, 20 MB download limit, HTTPS-only webhooks, up to 30 messages per second globally. The local API runs on your own server: 2 GB file limits, HTTP webhooks on any port, up to 100,000 concurrent connections.
How many concurrent connections does the local Telegram Bot API support?
The local Telegram Bot API server supports up to 100,000 concurrent webhook connections, significantly exceeding the standard API which is limited to specific ports (443, 80, 88, 8443).

// Contact

Need help?

Get in touch with me and I'll help solve the problem

Message on Telegram

Отвечаю в течение рабочего дня (03:00–13:00 GMT)

Или оставьте заявку здесь:

Send request
Write and get a quick reply