Amarula.Protocol.Binary.JID (amarula v0.1.0)
View SourceJID (Jabber ID) utilities for WhatsApp protocol. Ported from src/WABinary/jid-utils.ts
This module provides functions for encoding, decoding, and manipulating WhatsApp JIDs (Jabber IDs) with support for devices, agents, and different server types.
Summary
Functions
Compares two JIDs to see if they represent the same user.
Decodes a JID string into its components.
Encodes a JID from its components.
Checks if a JID represents a group. This is an alias for jid_group?/1 for compatibility with the messages module.
Checks if a JID represents a hosted LID user.
Checks if a JID represents a hosted PN user.
Checks if a JID represents a bot.
Checks if a JID represents a broadcast.
Checks if a JID represents a group.
Checks if a JID represents Meta AI.
Checks if a JID represents a newsletter.
Normalizes a JID to user format, converting c.us to s.whatsapp.net.
Checks if a JID is the status broadcast.
Checks if a JID represents a user (PN user).
Checks if a JID represents a LID user.
Returns the META_AI_JID constant
Returns the OFFICIAL_BIZ_JID constant
Returns the PSA_WID constant
Returns the S_WHATSAPP_NET constant
Returns the SERVER_JID constant
Returns the STORIES_JID constant
Transfers device from one JID to another.
Functions
Compares two JIDs to see if they represent the same user.
Decodes a JID string into its components.
Parameters
jid: The JID string to decode
Returns
A map with keys: :user, :server, :device (optional), :domain_type
Examples
iex> JID.decode("1234@s.whatsapp.net")
%{user: "1234", server: "s.whatsapp.net", domain_type: 0}
iex> JID.decode("1234:0@s.whatsapp.net")
%{user: "1234", device: 0, server: "s.whatsapp.net", domain_type: 0}
Encodes a JID from its components.
Parameters
user: The user identifier (string, number, or nil)server: The server part of the JID (optional, defaults to "s.whatsapp.net")device: Optional device numberagent: Optional agent number
Examples
iex> JID.encode(%{user: "1234", server: "s.whatsapp.net"})
"1234@s.whatsapp.net"
iex> JID.encode(%{user: "1234", device: 0, server: "s.whatsapp.net"})
"1234:0@s.whatsapp.net"
iex> JID.encode(%{user: "1234", agent: 1, server: "s.whatsapp.net"})
"1234_1@s.whatsapp.net"
Checks if a JID represents a group. This is an alias for jid_group?/1 for compatibility with the messages module.
Checks if a JID represents a hosted LID user.
Checks if a JID represents a hosted PN user.
Checks if a JID represents a bot.
Checks if a JID represents a broadcast.
Checks if a JID represents a group.
Checks if a JID represents Meta AI.
Checks if a JID represents a newsletter.
Normalizes a JID to user format, converting c.us to s.whatsapp.net.
Checks if a JID is the status broadcast.
Checks if a JID represents a user (PN user).
Checks if a JID represents a LID user.
@spec meta_ai_jid() :: binary()
Returns the META_AI_JID constant
@spec official_biz_jid() :: binary()
Returns the OFFICIAL_BIZ_JID constant
@spec psa_wid() :: binary()
Returns the PSA_WID constant
@spec s_whatsapp_net() :: binary()
Returns the S_WHATSAPP_NET constant
@spec server_jid() :: binary()
Returns the SERVER_JID constant
@spec stories_jid() :: binary()
Returns the STORIES_JID constant
Transfers device from one JID to another.