Amarula.Protocol.Groups.Metadata (amarula v0.1.0)

View Source

Group metadata: build the w:g2 query IQ and parse its result into the bits a group send needs. Port of Baileys groupQuery/extractGroupMetadata (src/Socket/groups.ts), trimmed to the send-relevant fields (participants + addressing mode); description/community/etc. are skipped until a consumer needs them.

Usage (the IQ goes through Connection.query_iq/2):

iq = Metadata.query_iq(group_jid)
{:ok, reply} = Connection.query_iq(conn, iq)
{:ok, meta} = Metadata.parse(reply)

Summary

Functions

Parse a group-metadata IQ result. Returns {:ok, metadata} or {:error, reason} (missing <group>, surfaced <error>, or missing id).

Parse an "all participating" IQ result (<groups><group>…</groups>) into a list of metadata maps. Unparseable group nodes are skipped.

Build the "all participating groups" query IQ (Baileys groupFetchAllParticipating)

Build the interactive group-metadata query IQ

Types

participant()

@type participant() :: %{
  id: String.t(),
  lid: String.t() | nil,
  phone_number: String.t() | nil,
  admin: String.t() | nil
}

t()

@type t() :: %{
  id: String.t(),
  subject: String.t() | nil,
  owner: String.t() | nil,
  addressing_mode: :pn | :lid,
  size: non_neg_integer(),
  participants: [participant()]
}

Functions

parse(result)

@spec parse(Amarula.Protocol.Binary.Node.t()) :: {:ok, t()} | {:error, term()}

Parse a group-metadata IQ result. Returns {:ok, metadata} or {:error, reason} (missing <group>, surfaced <error>, or missing id).

parse_all(result)

@spec parse_all(Amarula.Protocol.Binary.Node.t()) :: {:ok, [t()]}

Parse an "all participating" IQ result (<groups><group>…</groups>) into a list of metadata maps. Unparseable group nodes are skipped.

query_all_iq()

@spec query_all_iq() :: Amarula.Protocol.Binary.Node.t()

Build the "all participating groups" query IQ (Baileys groupFetchAllParticipating):

<iq to="@g.us" xmlns="w:g2" type="get">
  <participating><participants/><description/></participating></iq>

query_iq(group_jid)

@spec query_iq(String.t()) :: Amarula.Protocol.Binary.Node.t()

Build the interactive group-metadata query IQ:

<iq type=get xmlns=w:g2 to=<group>><query request=interactive/></iq>