Skip to main content

Querying Group Metadata

Retrieve complete information about a group, including participants, description, settings, and more.
const metadata = await sock.groupMetadata(jid)

console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)

Method Signature

groupMetadata(jid: string): Promise<GroupMetadata>
Parameters:
  • jid - The group JID
Returns: A GroupMetadata object containing:
  • id - Group JID
  • subject - Group name
  • subjectOwner - JID of who last changed the subject
  • subjectTime - Timestamp of last subject change
  • desc - Group description
  • descId - Description version ID
  • descOwner - JID of who set the description
  • descTime - Timestamp of last description change
  • participants - Array of participant objects with id, admin status, and more
  • size - Number of participants
  • owner - Group creator’s JID
  • creation - Group creation timestamp
  • restrict - Whether group settings are locked to admins only
  • announce - Whether only admins can send messages
  • ephemeralDuration - Disappearing messages duration (if enabled)
  • memberAddMode - Whether all members can add participants

Caching Group Metadata

For better performance, implement group metadata caching:
import NodeCache from 'node-cache'

const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })

const sock = makeWASocket({
  cachedGroupMetadata: async (jid) => groupCache.get(jid)
})

sock.ev.on('groups.update', async ([event]) => {
  const metadata = await sock.groupMetadata(event.id)
  groupCache.set(event.id, metadata)
})

sock.ev.on('group-participants.update', async (event) => {
  const metadata = await sock.groupMetadata(event.id)
  groupCache.set(event.id, metadata)
})
Caching group metadata is highly recommended if your application works with groups. This reduces API calls and improves performance.

Updating Group Settings

Configure who can send messages and modify group settings.

Message Permissions

// Only allow admins to send messages
await sock.groupSettingUpdate(jid, 'announcement')

// Allow everyone to send messages
await sock.groupSettingUpdate(jid, 'not_announcement')

Settings Permissions

// Only allow admins to modify group settings (picture, subject, etc.)
await sock.groupSettingUpdate(jid, 'locked')

// Allow everyone to modify the group's settings
await sock.groupSettingUpdate(jid, 'unlocked')

Method Signature

groupSettingUpdate(
  jid: string,
  setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked'
): Promise<void>
Parameters:
  • jid - The group JID
  • setting - One of:
    • 'announcement' - Only admins can send messages
    • 'not_announcement' - Everyone can send messages
    • 'locked' - Only admins can modify group settings
    • 'unlocked' - Everyone can modify group settings
You must be a group admin to update group settings.

Toggle Disappearing Messages

Enable or disable disappearing messages for a group.
// Enable disappearing messages (24 hours)
await sock.groupToggleEphemeral(jid, 86400)

// Enable disappearing messages (7 days)
await sock.groupToggleEphemeral(jid, 604800)

// Enable disappearing messages (90 days)
await sock.groupToggleEphemeral(jid, 7776000)

// Disable disappearing messages
await sock.groupToggleEphemeral(jid, 0)

Method Signature

groupToggleEphemeral(jid: string, ephemeralExpiration: number): Promise<void>
Parameters:
  • jid - The group JID
  • ephemeralExpiration - Duration in seconds:
    • 0 - Disable disappearing messages
    • 86400 - 24 hours
    • 604800 - 7 days
    • 7776000 - 90 days
When disappearing messages are enabled, all new messages in the group will automatically be deleted after the specified duration.

Member Add Mode

Control who can add new participants to the group.
// Allow all members to add new participants
await sock.groupMemberAddMode(jid, 'all_member_add')

// Only allow admins to add new participants
await sock.groupMemberAddMode(jid, 'admin_add')

Method Signature

groupMemberAddMode(
  jid: string,
  mode: 'admin_add' | 'all_member_add'
): Promise<void>
Parameters:
  • jid - The group JID
  • mode - Either:
    • 'admin_add' - Only admins can add participants
    • 'all_member_add' - All members can add participants

Fetching All Groups

Retrieve metadata for all groups you’re participating in.
const groups = await sock.groupFetchAllParticipating()
console.log(groups)

Method Signature

groupFetchAllParticipating(): Promise<{ [id: string]: GroupMetadata }>
Returns: An object mapping group JIDs to their GroupMetadata
This method emits a groups.update event with all the fetched group metadata.

Best Practices

1

Implement metadata caching

Use the cachedGroupMetadata socket config option to cache group data and reduce API calls.
2

Listen to update events

Subscribe to groups.update and group-participants.update events to keep your cache in sync.
3

Check admin status

Before changing settings, verify you have admin privileges by checking your status in the group metadata.
4

Handle settings appropriately

Consider your group’s purpose when configuring settings. Large announcement groups benefit from admin-only messaging.

Build docs developers (and LLMs) love