Skip to content

PAM WhatsApp Web

pushinbr/pam-whatsapp-web lets a PHP program act as a linked device on a WhatsApp account. It opens WhatsApp Web in a headless Chrome through PAM Browser, keeps the session alive in a persistent PAM process, and gives you a typed PHP API for messages, media, chats, groups, channels, and real-time events.

If you have used the Node.js library whatsapp-web.js, the API will feel familiar: version 1.2 tracks whatsapp-web.js 1.34.7 and maps its public symbols and members to PHP. There is no Node.js, npm, Puppeteer, or Playwright involved.

  • The PAM runtime (see Installation). The package requires PHP 8.5 and ext-mbstring, both included in PAM.
  • Google Chrome or Chromium on the host. Sending video requires Google Chrome, as in whatsapp-web.js.
  • A phone with WhatsApp to link the session the first time.
  • ffmpeg on the PATH only if you convert videos to stickers.
Terminal window
mkdir whatsapp-demo && cd whatsapp-demo
pam composer init --no-interaction
pam composer require pushinbr/pam-whatsapp-web:^1.2

This also installs pushinbr/pam-browser and chillerlan/php-qrcode.

Create listen.php. It prints a QR code in the terminal on the first run, stores the session in .sessions/, and prints every incoming message:

listen.php
<?php
declare(strict_types=1);
require __DIR__.'/vendor/autoload.php';
use Pam\WhatsApp\Auth\LocalAuth;
use Pam\WhatsApp\Auth\LocalAuthOptions;
use Pam\WhatsApp\Client;
use Pam\WhatsApp\ClientOptions;
use Pam\WhatsApp\Event\MessageReceived;
use Pam\WhatsApp\Event\QrCodeReceived;
use Pam\WhatsApp\Event\Ready;
use Pam\WhatsApp\TerminalQrCode;
$client = new Client(new ClientOptions(
authStrategy: new LocalAuth(new LocalAuthOptions(
clientId: 'main',
dataPath: __DIR__.'/.sessions',
)),
));
$client->onQrCode(static function (QrCodeReceived $event): void {
echo "Open WhatsApp > Linked devices > Link a device\n\n";
echo TerminalQrCode::render($event->code), "\n";
});
$client->onReady(static function (Ready $event): void {
echo "WhatsApp connected. Waiting for messages...\n";
});
$client->onMessage(static function (MessageReceived $event): void {
$message = $event->message;
if ($message->body === '!ping') {
$message->reply('pong');
}
printf("[%s] %s: %s\n", date('H:i:s', $message->timestamp), $message->from, $message->body);
});
$client->initialize();
$client->run();

Run it:

Terminal window
pam listen.php

Scan the QR code from WhatsApp > Linked devices > Link a device on your phone. Once the session is ready, send !ping to the linked account from another phone and it answers pong. The next time you start the script, the saved session in .sessions/ reconnects without a new QR code.

your PHP code
│
▼
PAM WhatsApp Web ── typed events and objects
│
▼
PAM Browser ─────── Chrome DevTools Protocol
│
▼
Chrome / Chromium ─ WhatsApp Web

initialize() launches the browser, loads WhatsApp Web, and injects a bridge script. The bridge calls WhatsApp Web’s own modules and sends events back to PHP. run() then processes those events until the client is closed or fails. Every operation is a method call on a typed PHP object; arguments and results are converted at the bridge boundary.

Area Features
Sessions QR code, pairing code, LocalAuth, RemoteAuth, opt-in reconnection, conflict takeover, diagnostics
Messages Text, replies, edits, deletion, forwarding, reactions, mentions, stars, pins, read receipts
Media Images, audio and voice notes, video, documents, stickers, streaming downloads
Conversations Contacts, private chats, groups, participants, invites, membership requests, labels
Content Locations, polls, contact cards, scheduled events, legacy buttons and lists
Platform Presence, connection state, calls, channels, business profiles, products, orders