PAM Telegram Web
pushinbr/pam-telegram-web connects PHP to a Telegram user account, not a bot. It logs into Telegram Web in a headless Chrome through PAM Browser, and gives you typed chats, messages, and events, plus access to every method of the Telegram API through the web client’s own connection.
Because Telegram Web does the protocol work, you do not need Node.js, Puppeteer, or an api_id from my.telegram.org. Messages you send appear on all your devices, just as if you had typed them in Telegram Web.
Requirements
Section titled “Requirements”- The PAM runtime (see Installation). The package requires PHP 8.5 and
ext-gd, both included in PAM. - Google Chrome or Chromium on the host.
- Telegram on a phone, to scan the login QR code.
Installation
Section titled “Installation”mkdir telegram-demo && cd telegram-demopam composer init --no-interactionpam composer require pushinbr/pam-telegram-web:^0.3Quick start
Section titled “Quick start”<?php
declare(strict_types=1);
require __DIR__.'/vendor/autoload.php';
use Pam\TelegramWeb\Client;use Pam\TelegramWeb\Event\MessageReceived;use Pam\TelegramWeb\Event\QrCodeReceived;use Pam\TelegramWeb\Event\Ready;
$client = new Client();
$client->onQrCode(static function (QrCodeReceived $event): void { echo "Open Telegram > Settings > Devices > Link Desktop Device\n\n"; echo $event->terminal(), "\n";});
$client->onPasswordRequired(static function () use ($client): void { echo 'Two-step verification password: '; $client->submitPassword(rtrim((string) fgets(STDIN), "\r\n"));});
$client->onReady(static function (Ready $event) use ($client): void { echo "Connected as {$event->me?->name()}\n";
foreach ($client->getChats(10) as $chat) { printf(" %-8s %3d unread %s\n", $chat->type->value, $chat->unreadCount, $chat->title); }});
$client->onMessage(static function (MessageReceived $event): void { $message = $event->message; echo "[{$message->chatTitle}] {$message->fromName}: {$message->text}\n";
if (!$message->outgoing && strtolower($message->text) === 'ping') { $message->reply('pong'); }});
try { $client->run();} finally { $client->close();}pam listen.phpScan the QR code with your phone, and type your two-step verification password if your account has one. The login is saved in .pam-telegram-web/session, so the next run connects directly. Ctrl+C stops the loop, and the finally block closes the browser.
How it works
Section titled “How it works”your PHP code │ ▼PAM Telegram Web ── typed chats, messages and events │ ▼PAM Browser ─────── Chrome DevTools Protocol │ ▼Chrome / Chromium ─ Telegram Web (web.telegram.org/k) ── MTProto ── TelegramA bridge script in the page reads the login QR code, follows the web client’s update events, and calls its API layer. Telegram Web handles the protocol, encryption, and storage; PHP decodes the QR code and turns everything else into typed objects.