BaileysEx.Message.Decode (baileys_ex v0.1.0-alpha.9)

Copy Markdown View Source

Envelope decode helpers aligned with Baileys' message addressing rules.

The decoded envelope intentionally keeps two sender identities:

  • author_jid is the message author for higher-level message semantics and logs
  • signal_author_jid is the sender identity Signal group crypto should key on

Those values are usually the same, but direct device-addressed payloads can carry a bare chat author in from and the device-qualified sender in participant. Group sender-key distribution and skmsg decrypts must use the device-qualified identity, while normalized received messages should continue to expose the stable author JID.

Summary

Functions

Decodes a protocol envelope from the given binary node, analyzing addressing.

Extracts basic addressing details (mode and alternate identifiers) from a node.

Types

context()

@type context() :: %{
  :signal_repository => BaileysEx.Signal.Repository.t(),
  :me_id => String.t(),
  optional(:me_lid) => String.t(),
  optional(atom()) => term()
}

envelope()

@type envelope() :: %{
  :remote_jid => String.t(),
  optional(:remote_jid_alt) => String.t(),
  optional(:participant) => String.t(),
  optional(:participant_alt) => String.t(),
  optional(:server_id) => String.t(),
  from_me: boolean(),
  author_jid: String.t(),
  signal_author_jid: String.t(),
  decryption_jid: String.t(),
  addressing_mode: :pn | :lid
}

Functions

decode_envelope(node, context)

@spec decode_envelope(BaileysEx.BinaryNode.t(), context()) ::
  {:ok, envelope(), context()} | {:error, term()}

Decodes a protocol envelope from the given binary node, analyzing addressing.

The returned envelope separates message semantics from crypto semantics so later pipeline stages do not need to rediscover which sender identity Signal should use.

extract_addressing_context(binary_node)

Extracts basic addressing details (mode and alternate identifiers) from a node.