JIDs (Jabber IDs) are unique identifiers used in WhatsApp to identify users, groups, and other entities. A JID typically follows the format user@server where:
user: The unique identifier (phone number for users, group ID for groups)
server: The WhatsApp server domain (e.g., s.whatsapp.net, g.us, lid)
The JID utilities module provides functions to parse, normalize, and validate WhatsApp JIDs.
All JID utility functions accept unknown types and safely handle type conversion, making them safe to use with any input.
import { normalize } from 'wapi/utils/jid';const normalized = normalize('1234567890:0@s.whatsapp.net');console.log(normalized);// '1234567890@s.whatsapp.net'
Normalizing JIDs is important when storing or comparing them, as WhatsApp may send JIDs with device identifiers that should be ignored for identification purposes.
import { normalize, isPn } from 'wapi/utils/jid';command('add', async (ctx) => { const userInput = ctx.args[0]; // e.g., "1234567890@s.whatsapp.net" // Normalize to remove device IDs const normalized = normalize(userInput); // Validate it's a personal number if (!isPn(normalized)) { await ctx.reply('Please provide a valid user JID!'); return; } // Safe to use await addUserToList(normalized);});