
MadelineProto
Full-featured async PHP Telegram MTProto client
Replaces —

Who it's for
A PHP developer who needs to automate Telegram actions from a user account, such as joining channels, forwarding messages, or scraping content, can log in with a phone number and call any MTProto method the official apps support.
You only need standard bot commands and callbacks covered by the Bot API.
A developer building a bot that sends or receives files larger than the Bot API's 50 MB upload and 20 MB download limits can use MadelineProto's parallelized transfer methods to handle files up to 4 GB.
All files you handle are under the Bot API size limits.
A developer who wants to build a Telegram voice radio, video broadcast bot, or call-recording tool can use MadelineProto's calls API to stream WebM audio or video into calls and group livestreams without requiring ffmpeg on the host.
Your project does not involve voice or video calls.
A developer building end-to-end encrypted automation, such as a secret chat echo bot or a secure messaging relay, can use MadelineProto's secret chat API to request, accept, and exchange messages in encrypted conversations.
Your bot operates only in standard (non-secret) chats.
The problem
Telegram's official Bot API restricts what bots and automations can do: file transfers are capped, user-account features are unavailable, and the full MTProto surface is hidden. Developers who need capabilities matching those of Telegram's own apps, such as user-account login, large file transfers, voice/video calls, or secret chats, have no path through the Bot API alone.
How it works
Communicates with Telegram using the native MTProto protocol rather than the Bot API, exposing every API method available to official clients. Both phone-number login and bot-token login are supported without the Bot API layer.
Built on AMPHP v3 and PHP fibers for concurrent, non-blocking execution. Multiple async operations can run in parallel using helper methods, enabling high-throughput bots and userbots without blocking I/O.
Make and receive one-to-one VoIP and video calls, stream WebM video files without ffmpeg, join and manage group video chats and livestreams, record calls, and participate in end-to-end encrypted conference calls.
Upload and download files up to 4 GB using fully parallelized wrappers that accept bot API file IDs, direct URLs, or local files. Download targets include streams, browsers, HTTP servers, directories, and callbacks.
A native plugin system based on PHP event handlers lets developers compose reusable functionality. Message filtering uses PHP's type system and attributes, including simple filters, attribute filters, and raw MTProto filters.
Internal state can be stored in MySQL, MariaDB, Postgres, or Redis instead of memory, reducing RAM usage for long-running bots. A custom backend can also be implemented using the provided interface.
Features
- Direct MTProto access
- Fully async with AMPHP
- Voice, video, and group calls
- Large file transfers
- Plugin and filter system
- Flexible database backends
How to install
<?php if (!file_exists('madeline.php')) { copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php'); } include 'madeline.php'; $MadelineProto = new \danog\MadelineProto\API('session.madeline'); $MadelineProto->start();
Recommended for this setup
Strengths
- Full Telegram feature parity: Because it speaks MTProto directly, MadelineProto can do everything official Telegram clients can do, including features the Bot API does not expose, such as user-account actions, secret chats, and the full calls API.
- Approved by Telegram: The project carries official Telegram approval, reducing concern about policy violations when building user-account clients with it.
- Simple installation: The quickest setup is a single file include: copy `madeline.php` from the official phar host, include it, and instantiate the API class. Composer installation from an existing project or from scratch is also supported.
- Standalone companion libraries: Core components are published as independent packages, including an async ORM, a Telegram UTF-16 text entities library, a bot API file ID decoder, a dialog ID helper, and an async DNS-over-HTTPS resolver, usable without pulling in the full library.
Trade-offs
- PHP 8.2 or later required: MadelineProto depends on PHP fibers, which require PHP 8.2 as a minimum. Projects running older PHP versions cannot use it without a runtime upgrade.
- Several PHP extensions required: The library requires mbstring, xml, json, fileinfo, gmp, openssl, iconv, and gd to be installed and enabled. Shared hosting environments that restrict extensions may not be compatible.
- Userbot use carries Telegram account risk: Logging in as a user account and automating actions beyond what Telegram permits can result in account restrictions. Developers must stay within Telegram's usage policies when operating userbots.
- Steeper learning curve than the Bot API: Working at the MTProto level exposes a much larger and lower-level API surface than the Bot API. Developers new to Telegram development may find the Bot API wrappers (python-telegram-bot, telegraf, etc.) easier to start with if they do not need MTProto-specific features.
Tech stack
FAQ
No. MadelineProto communicates directly with the Telegram MTProto protocol, bypassing the Bot API entirely. Even when logging in with a bot token, the requests go to MTProto, not the Bot API servers.
The simplest method is to copy `madeline.php` from `https://phar.madelineproto.xyz/madeline.php` and include it in your script. Composer installation is also supported, both from an existing project and from scratch.
Yes. Multi-account support is documented and each account uses its own session file passed to the API constructor.
In addition to the default in-memory backend, MadelineProto supports MySQL, MariaDB, Postgres, and Redis for storing internal state, which reduces RAM usage for long-running processes.
Yes. An official image is available at `hub.madelineproto.xyz/danog/madelineproto` for the `linux/amd64` and `linux/arm64` platforms, with documented tags for CLI bots, web deployments, databases, and custom extensions.