Overview
This guide covers group operations including creation, participant management, and metadata updates using the whatsapp-rust library.Accessing the groups API
All group operations are accessed through thegroups() method:
Creating groups
Basic group creation
Group creation options
Group constraints
GroupCreateOptions.subject is a plain String. Validated types GroupSubject and GroupDescription are used by set_subject and set_description respectively.Querying group information
Get group metadata
List all groups
Query group info (internal)
For lower-level access with caching:Updating group metadata
Change group subject
Set or delete group description
The
prev parameter can be used for conflict detection. If provided and the current description ID doesn’t match, the operation may fail. Pass None if you don’t need this check.Managing participants
Add participants
Remove participants
Promote to admin
Demote admin
Leave group
Group invite links
Get invite link
Join a group via invite
You can join a group using an invite code or a fullhttps://chat.whatsapp.com/... URL. The method automatically strips the URL prefix if present.
PendingApproval instead of Joined.
See Groups API reference for details.
Accept a V4 invite message
V4 invites are sent directly by a group admin as aGroupInviteMessage, rather than shared as a URL. Use join_with_invite_v4 to accept these invites:
V4 invites have an expiration timestamp. The method automatically checks whether the invite has expired and returns an error if it has. Pass
0 as the expiration to skip the check.Preview a group before joining
Useget_invite_info to fetch group metadata from an invite code without joining:
Membership requests
When a group has membership approval enabled, new members must be approved by an admin. You can view, approve, and reject pending requests.Get pending requests
Approve or reject requests
You must be a group admin to view, approve, or reject membership requests.
Cancel membership requests
Users can cancel their own pending membership requests:Revoke invitation codes
Admins can revoke invitation codes from specific participants:Batch operations
Batch query group info
Query metadata for multiple groups in a single request (up to 10,000 groups):Batch fetch profile pictures
Fetch profile pictures for multiple groups at once (up to 1,000 groups):Set or remove the group picture
Admins can update the group’s profile picture by uploading JPEG bytes, or remove it with a dedicated call:Group settings
Member add mode
Control who can add new members:Membership approval mode
Require admin approval for new members:Announcement mode
Toggle announcement mode on an existing group (only admins can send messages):Frequently-forwarded messages
Restrict or allow frequently-forwarded messages in the group:Admin reports
Enable or disable admin reports in the group:Group history sharing
Enable or disable sharing group history with new members:Member link mode
Control who can share invite links. This setting is updated via the MEX protocol:Message history sharing mode
Control who can share message history with new members. This setting is updated via the MEX protocol:Limit sharing
Enable or disable limit sharing in the group. This setting is updated via the MEX protocol:Privacy tokens on group operations
When server-side A/B experiment flags are enabled, the library automatically attaches privacy tokens (tc_token) to participants during group creation and participant addition. This matches WhatsApp Web’s behavior and requires no changes to your code.
The following AB prop flags control this behavior:
These flags are fetched from the server automatically on each connection via
fetch_props(). Token resolution uses the LID-to-phone-number cache and the tc_token store — if a valid, non-expired token exists for a participant, it is attached to the IQ request.
Privacy token attachment is fully automatic. You don’t need to call any extra methods or manage tokens manually. If the AB flags are disabled on the server, group operations work exactly as before.
Addressing modes
Groups can use different addressing modes:LID (Long ID) mode provides better privacy by hiding phone numbers. The library automatically handles LID-to-phone-number mapping when needed.
Participant response codes
When adding or removing participants, check the response codes:Error handling
Advanced usage
Handling LID groups
For LID-based groups, you may need phone number mappings:Participant options
For advanced participant configurations:Best practices
1
Validate input before creating groups
2
// ✅ Good: Validate before creation
let subject = match GroupSubject::new(user_input) {
Ok(s) => s,
Err(e) => {
eprintln!("Invalid subject: {}", e);
return Err(e);
}
};
// ❌ Bad: No validation
let subject = GroupSubject::new(user_input)?; // May panic on invalid input
3
Check response codes
4
Always check participant operation responses:
5
let responses = client.groups().add_participants(&group_jid, &participants).await?;
let mut success_count = 0;
let mut failed = Vec::new();
for response in responses {
if response.status.as_deref() == Some("200") {
success_count += 1;
} else {
failed.push(response);
}
}
println!("Added {} participants", success_count);
if !failed.is_empty() {
eprintln!("Failed to add {} participants", failed.len());
}
6
Handle addressing modes
7
Be aware of LID vs PN addressing:
8
let info = client.groups().query_info(&group_jid).await?;
if info.addressing_mode == AddressingMode::Lid {
// Handle LID-based group
// Phone numbers may not be directly visible
} else {
// Handle phone-number-based group
}
9
Cache group information
10
The library automatically caches group info:
11
// First call: fetches from server
let info = client.groups().query_info(&group_jid).await?;
// Second call: uses cache
let info = client.groups().query_info(&group_jid).await?;
Next steps
- Community management - Create and manage communities with linked subgroups
- Sending messages - Send messages to groups
- Receiving messages - Handle group message events
- Custom backends - Store group metadata