JID (Jabber ID) parsing, formatting, and utility functions for WhatsApp addressing.
Handles all WhatsApp JID formats including users, groups, broadcasts, LID (Local Identifier) addresses, newsletters, and device-specific addresses.
Summary
Functions
Detect the addressing mode from a JID.
Returns the broadcast domain identifier.
Check if JID represents a broadcast.
Get the domain type byte for AD_JID encoding based on server.
Returns the group domain identifier.
Check if JID represents a group.
Check if JID is a hosted LID.
Check if JID is a hosted PN.
Construct a JID string from component parts.
Returns the LID domain identifier.
Check if JID is a LID (Local Identifier).
Returns the newsletter domain identifier.
Check if JID represents a newsletter.
Normalize a JID for comparison.
Parse a JID string into a BaileysEx.JID struct.
Returns the standard WhatsApp network domain identifier.
Check if two JIDs belong to the same user (ignoring device).
Get the server string from a domain type byte.
Check if JID is the status broadcast.
Normalize JID for Signal protocol addressing.
Format a JID struct back to its string representation.
Check if JID represents a user (on s.whatsapp.net).
Functions
@spec addressing_mode(BaileysEx.JID.t()) :: :lid | :pn
Detect the addressing mode from a JID.
@spec broadcast() :: String.t()
Returns the broadcast domain identifier.
@spec broadcast?(BaileysEx.JID.t() | String.t() | nil) :: boolean()
Check if JID represents a broadcast.
@spec domain_type_for_server(String.t()) :: non_neg_integer()
Get the domain type byte for AD_JID encoding based on server.
@spec g_us() :: String.t()
Returns the group domain identifier.
@spec group?(BaileysEx.JID.t() | String.t() | nil) :: boolean()
Check if JID represents a group.
@spec hosted_lid?(BaileysEx.JID.t() | String.t() | nil) :: boolean()
Check if JID is a hosted LID.
@spec hosted_pn?(BaileysEx.JID.t() | String.t() | nil) :: boolean()
Check if JID is a hosted PN.
@spec jid_encode( String.t() | nil, String.t(), non_neg_integer() | nil, non_neg_integer() | nil ) :: String.t()
Construct a JID string from component parts.
Follows Baileys jidEncode convention:
- Agent is appended as
_agentsuffix on user - Device is appended as
:devicesuffix - Result:
"user_agent:device@server"
@spec lid() :: String.t()
Returns the LID domain identifier.
@spec lid?(BaileysEx.JID.t() | String.t() | nil) :: boolean()
Check if JID is a LID (Local Identifier).
@spec newsletter() :: String.t()
Returns the newsletter domain identifier.
@spec newsletter?(BaileysEx.JID.t() | String.t() | nil) :: boolean()
Check if JID represents a newsletter.
Normalize a JID for comparison.
Strips device info and normalizes c.us to s.whatsapp.net.
@spec parse(String.t() | nil) :: BaileysEx.JID.t() | nil
Parse a JID string into a BaileysEx.JID struct.
Handles formats:
"user@server"— basic JID"user:device@server"— JID with device ID"user_agent:device@server"— JID with agent and device"@server"— server-only JID (nil user)
Returns nil if the string has no @ separator.
@spec s_whatsapp_net() :: String.t()
Returns the standard WhatsApp network domain identifier.
Check if two JIDs belong to the same user (ignoring device).
@spec server_from_domain_type(non_neg_integer(), String.t()) :: String.t()
Get the server string from a domain type byte.
@spec status_broadcast?(BaileysEx.JID.t() | String.t()) :: boolean()
Check if JID is the status broadcast.
@spec to_signal_address(BaileysEx.JID.t()) :: BaileysEx.JID.t()
Normalize JID for Signal protocol addressing.
Strips device number, keeps user and server.
@spec to_string(BaileysEx.JID.t()) :: String.t()
Format a JID struct back to its string representation.
Produces "user_agent:device@server" format, omitting agent and device
parts when they are nil or 0.
@spec user?(BaileysEx.JID.t() | String.t() | nil) :: boolean()
Check if JID represents a user (on s.whatsapp.net).