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)' : '', );}
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().
Contacts
Section titled “Contacts”
echo $contact->pushname, PHP_EOL; // the name the user setecho $contact->number, PHP_EOL;echo $contact->getAbout() ?? '', PHP_EOL;
$contact->block();$contact->unblock();
$client->getContacts();$client->getBlockedContacts();Contact exposes id, number, name, pushname, shortName, isBusiness, isMyContact, isBlocked, and more. Business accounts are returned as BusinessContact, which adds a businessProfile.
Groups
Section titled “Groups”Creating a group
Section titled “Creating a group”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.
Managing a group
Section titled “Managing a group”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);
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.
Invites and membership requests
Section titled “Invites and membership requests”$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.
Channels
Section titled “Channels”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 and notes
Section titled “Labels and notes”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');
Account and profile
Section titled “Account and profile”$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