Skip to main content

Overview

Baileys provides comprehensive methods for working with WhatsApp group invite codes. You can generate invite links, revoke them, join groups using codes, and get information about groups before joining.

Getting Invite Codes

Retrieve the current invite code for a group.

Function Signature

Parameters:
  • jid - The group JID
Returns: The invite code as a string

Get Invite Code

Only group admins can retrieve the invite code.
To create a clickable WhatsApp invite link:

Complete Example

Revoking Invite Codes

Revoke the current invite code and generate a new one.

Function Signature

Parameters:
  • jid - The group JID
Returns: The new invite code

Revoke and Get New Code

Revoking an invite code immediately invalidates all previously shared invite links. Users with old links won’t be able to join.

Safe Revoke Pattern

Revoking V4 Invites

Revoke a specific user’s V4 invite.

Function Signature

Parameters:
  • groupJid - The group JID
  • invitedJid - JID of the person whose invite you want to revoke
Returns: true if successful

Revoke Specific User’s Invite

Joining Groups with Invite Codes

Join a group using an invite code.

Function Signature

Parameters:
  • code - The invite code (without the URL prefix)
Returns: The group JID you joined

Join Using Code

The code parameter should be only the code, not the full URL. Extract it from https://chat.whatsapp.com/CODE

Join with Error Handling

Joining with GroupInviteMessage (V4)

Accept a group invite using a GroupInviteMessage.

Function Signature

Parameters:
  • key - The message key or sender JID
  • inviteMessage - The GroupInviteMessage object
Returns: The group JID

Accept V4 Invite

Handle GroupInviteMessage from Events

When you accept a V4 invite, the library automatically expires the invite message in your chat.

Getting Group Info Before Joining

Fetch group metadata using just the invite code, without joining.

Function Signature

Parameters:
  • code - The invite code (without URL prefix)
Returns: GroupMetadata object with group information

Get Group Information

Preview Group Before Joining

Complete Invite Management System

Comprehensive example combining all invite functionality:
1

Generate and share invite

2

Manage invite security

3

Smart join with validation

Best Practices

Rate Limiting: Don’t revoke invite codes too frequently. WhatsApp may rate-limit this operation.
Preview Before Joining: Always use groupGetInviteInfo to check group details before joining with groupAcceptInvite.
Code Format: When using invite codes, ensure you pass only the code portion, not the full URL.

Security Tips

  1. Regular Rotation: Periodically revoke and regenerate invite codes for sensitive groups
  2. Approval Mode: Enable join approval mode for additional security
  3. Validate Before Joining: Check group size and description before auto-joining
  4. Track Invites: Keep logs of when invite codes are generated and shared

Helper Functions

Common Use Cases

Automated Invite Distribution