Skip to main content

Creating a Group

You can create a new WhatsApp group by providing a name (subject) and a list of participant JIDs.
const group = await sock.groupCreate(
  'My Fab Group',
  ['[email protected]', '[email protected]']
)

console.log('created group with id: ' + group.id)

// Send a welcome message to the group
await sock.sendMessage(group.id, { text: 'hello there' })

Method Signature

groupCreate(subject: string, participants: string[]): Promise<GroupMetadata>
Parameters:
  • subject - The name of the group
  • participants - Array of participant JIDs in the format [country code][phone number]@s.whatsapp.net
Returns: A GroupMetadata object containing the group’s ID and other metadata
You must include at least one participant when creating a group. Group IDs are in the format [email protected].

Updating Group Subject

Change the group’s name (subject) using the groupUpdateSubject method.
await sock.groupUpdateSubject(jid, 'New Subject!')

Method Signature

groupUpdateSubject(jid: string, subject: string): Promise<void>
Parameters:
  • jid - The group JID
  • subject - The new group name
You must be a group admin to update the subject. The operation will fail if you don’t have admin privileges.

Updating Group Description

Update or remove the group’s description.
// Set a new description
await sock.groupUpdateDescription(jid, 'New Description!')

// Remove the description
await sock.groupUpdateDescription(jid, undefined)

Method Signature

groupUpdateDescription(jid: string, description?: string): Promise<void>
Parameters:
  • jid - The group JID
  • description - The new description text, or undefined to remove it
The method automatically handles description versioning by retrieving the current description ID before updating.

Leaving a Group

You can leave a group using the groupLeave method.
// Leave the group
await sock.groupLeave(jid)

Method Signature

groupLeave(id: string): Promise<void>
Parameters:
  • id - The group JID
This operation will throw an error if it fails. Once you leave a group, you’ll need an invite to rejoin.

Best Practices

1

Verify admin status

Before attempting to modify group properties, ensure you have admin privileges using groupMetadata to check your participant status.
2

Handle errors gracefully

Wrap group operations in try-catch blocks, as they will throw errors if you lack permissions or if the operation fails.
3

Cache group metadata

Implement group metadata caching to reduce API calls. See the Settings & Metadata page for details.

Build docs developers (and LLMs) love