BaileysEx.Protocol.JID (baileys_ex v0.1.0-alpha.8)

Copy Markdown View Source

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

addressing_mode(jid)

@spec addressing_mode(BaileysEx.JID.t()) :: :lid | :pn

Detect the addressing mode from a JID.

broadcast()

@spec broadcast() :: String.t()

Returns the broadcast domain identifier.

broadcast?(jid)

@spec broadcast?(BaileysEx.JID.t() | String.t() | nil) :: boolean()

Check if JID represents a broadcast.

domain_type_for_server(arg1)

@spec domain_type_for_server(String.t()) :: non_neg_integer()

Get the domain type byte for AD_JID encoding based on server.

g_us()

@spec g_us() :: String.t()

Returns the group domain identifier.

group?(jid)

@spec group?(BaileysEx.JID.t() | String.t() | nil) :: boolean()

Check if JID represents a group.

hosted_lid?(jid)

@spec hosted_lid?(BaileysEx.JID.t() | String.t() | nil) :: boolean()

Check if JID is a hosted LID.

hosted_pn?(jid)

@spec hosted_pn?(BaileysEx.JID.t() | String.t() | nil) :: boolean()

Check if JID is a hosted PN.

jid_encode(user, server, device \\ nil, agent \\ nil)

@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 _agent suffix on user
  • Device is appended as :device suffix
  • Result: "user_agent:device@server"

lid()

@spec lid() :: String.t()

Returns the LID domain identifier.

lid?(jid)

@spec lid?(BaileysEx.JID.t() | String.t() | nil) :: boolean()

Check if JID is a LID (Local Identifier).

newsletter()

@spec newsletter() :: String.t()

Returns the newsletter domain identifier.

newsletter?(jid)

@spec newsletter?(BaileysEx.JID.t() | String.t() | nil) :: boolean()

Check if JID represents a newsletter.

normalized_user(jid)

@spec normalized_user(String.t() | nil) :: String.t()

Normalize a JID for comparison.

Strips device info and normalizes c.us to s.whatsapp.net.

parse(jid_string)

@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.

s_whatsapp_net()

@spec s_whatsapp_net() :: String.t()

Returns the standard WhatsApp network domain identifier.

same_user?(jid1, jid2)

@spec same_user?(String.t() | nil, String.t() | nil) :: boolean()

Check if two JIDs belong to the same user (ignoring device).

server_from_domain_type(arg1, default)

@spec server_from_domain_type(non_neg_integer(), String.t()) :: String.t()

Get the server string from a domain type byte.

status_broadcast?(jid)

@spec status_broadcast?(BaileysEx.JID.t() | String.t()) :: boolean()

Check if JID is the status broadcast.

to_signal_address(jid)

@spec to_signal_address(BaileysEx.JID.t()) :: BaileysEx.JID.t()

Normalize JID for Signal protocol addressing.

Strips device number, keeps user and server.

to_string(jid)

@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.

user?(jid)

@spec user?(BaileysEx.JID.t() | String.t() | nil) :: boolean()

Check if JID represents a user (on s.whatsapp.net).