Skip to content

Chats, Groups & Channels

Beyond sending messages, the client exposes the account’s chats, contacts, groups, and channels as typed objects. A private conversation is a Chat, a group is a GroupChat (which extends Chat), and a WhatsApp channel is a Channel.

use Pam\WhatsApp\GroupChat;
foreach ($client->getChats() as $chat) {
printf(
"%-40s %s unread=%d%s\n",
$chat->id->serialized,
$chat->name,
$chat->unreadCount,
$chat instanceof GroupChat ? ' (group)' : '',
);
}
$chat = $client->getChatById('[email protected]'); // Chat|Channel

A Chat has id, name, isGroup, isMuted, isReadOnly, archived, pinned, timestamp, unreadCount, and lastMessage, plus methods for the common actions:

use Pam\WhatsApp\MessageSearchOptions;
$chat->sendMessage('Hello from Acme');
$messages = $chat->fetchMessages(new MessageSearchOptions(limit: 20));
$chat->archive();
$chat->unarchive();
$chat->pin();
$chat->unpin();
$chat->mute(new DateTimeImmutable('+8 hours')); // null mutes indefinitely
$chat->unmute();
$chat->markUnread();
$chat->sendSeen();
$chat->clearMessages();
$chat->delete();

The client offers the same actions by ID, which saves a lookup: archiveChat(), unarchiveChat(), pinChat(), unpinChat(), muteChat(), unmuteChat(), markChatUnread(), and sendSeen().

$contact = $client->getContactById('[email protected]');
echo $contact->pushname, PHP_EOL; // the name the user set
echo $contact->number, PHP_EOL;
echo $contact->getAbout() ?? '', PHP_EOL;
$contact->block();
$contact->unblock();
$client->isRegisteredUser('[email protected]');
$client->getContacts();
$client->getBlockedContacts();
$client->getCommonGroups('[email protected]');

Contact exposes id, number, name, pushname, shortName, isBusiness, isMyContact, isBlocked, and more. Business accounts are returned as BusinessContact, which adds a businessProfile.

use Pam\WhatsApp\CreateGroupResult;
$result = $client->createGroup('Acme launch team', [
]);
if ($result instanceof CreateGroupResult) {
echo "Created {$result->gid->serialized}\n";
}

createGroup() returns a CreateGroupResult with the new group’s gid, its title, and a per-participant result, or an error string when WhatsApp rejects the request. Pass CreateGroupOptions as the third argument for settings such as messageTimer or membershipApprovalMode.

Load the chat and check that it is a GroupChat:

use Pam\WhatsApp\GroupChat;
$group = $client->getChatById($groupId);
if ($group instanceof GroupChat) {
$group->setSubject('Acme customers');
$group->setDescription('Support and product announcements');
$group->setMessagesAdminsOnly(true);
$group->setInfoAdminsOnly(true);
$group->setAddMembersAdminsOnly(true);
$group->addParticipants(['[email protected]']);
$group->removeParticipants(['[email protected]']);
$group->promoteParticipants(['[email protected]']);
$group->demoteParticipants(['[email protected]']);
foreach ($group->participants as $participant) {
echo $participant->id->serialized, $participant->isAdmin ? ' (admin)' : '', PHP_EOL;
}
}

Administrative actions only succeed when the linked account is a group admin.

$code = $group->getInviteCode(); // https://chat.whatsapp.com/{code}
$group->revokeInvite();
$joinedGroupId = $client->acceptInvite('AbCdEfGhIjKlMnOpQrStUv'); // the code, not the URL
$info = $client->getInviteInfo('AbCdEfGhIjKlMnOpQrStUv');
$requests = $group->getGroupMembershipRequests();
$group->approveGroupMembershipRequests();
$group->rejectGroupMembershipRequests();
$group->leave();

Group changes made by anyone (joins, leaves, admin changes, subject updates) arrive as group notification events.

use Pam\WhatsApp\CreateChannelOptions;
use Pam\WhatsApp\SearchChannelsOptions;
$channels = $client->getChannels();
$created = $client->createChannel('Acme product news', new CreateChannelOptions(
description: 'Release announcements',
));
$channel = $channels[0] ?? null;
$channel?->sendMessage('Version 2.0 is out!');
$channel?->setDescription('Release notes and tips');
$channel?->getSubscribers(50);
$client->subscribeToChannel($channelId);
$client->unsubscribeFromChannel($channelId);
$found = $client->searchChannels(new SearchChannelsOptions(searchText: 'acme', limit: 10));

Channel administration (sendChannelAdminInvite(), demoteChannelAdmin(), transferChannelOwnership(), deleteChannel()) is available on both Channel and Client.

Labels are a WhatsApp Business feature:

foreach ($client->getLabels() as $label) {
echo "{$label->id} {$label->name} {$label->hexColor}\n";
}
$client->addOrRemoveLabels(['1'], [$chatId]);
$chats = $client->getChatsByLabelId('1');
$client->addOrEditCustomerNote('[email protected]', 'Prefers email follow-ups');
$client->info?->pushname; // the linked account's display name
$client->info?->wid->serialized; // the linked account's ID
$client->setDisplayName('Acme Support');
$client->setStatus('Available 9:00 to 18:00');
$client->getWWebVersion(); // WhatsApp Web build in use
$client->getState(); // ConnectionState