Amarula.Protocol.Presence (amarula v0.1.0)
View SourceBuild presence / chat-state stanzas, ported from Baileys sendPresenceUpdate
and presenceSubscribe (src/Socket/chats.ts).
Pure stanza construction; the Connection supplies me and writes the
node. Two kinds:
- global presence —
available/unavailable:<presence name= type=>. - chat state —
composing/recording/pausedtoward a jid:<chatstate from= to=><composing|paused/></chatstate>.recordingis acomposingtag withmedia: "audio".
Summary
Types
A parsed inbound presence/chat-state update (Baileys presence.update)
Functions
A chat-state (typing) stanza toward to_jid. from is me.lid when to_jid
is a lid jid, else me.id.
Parse an inbound <presence> or <chatstate> node into an update/0
(Baileys handlePresenceUpdate). Returns {:error, :invalid} for a malformed
node. from/participant are returned as wire jid strings.
Global online/offline presence. me is the auth creds me map (needs :name;
Baileys skips the update without one). Returns {:ok, node} or
{:error, :no_name}.
A <presence type=subscribe> stanza for to_jid (tcToken omitted).
Types
@type chatstate() :: :composing | :recording | :paused
@type presence() :: :available | :unavailable
@type update() :: %{ jid: String.t(), participant: String.t(), presence: presence() | :composing | :recording, last_seen: integer() | nil }
A parsed inbound presence/chat-state update (Baileys presence.update):
:jid— the chat the update is for (attrs.from):participant— who within the chat (group member, or the contact itself):presence—:available/:unavailable(a<presence>) or:composing/:recording/:paused→:available(a<chatstate>):last_seen— unix seconds from a<presence last=>(nil otherwise)
Functions
@spec chatstate(chatstate(), String.t(), map()) :: Amarula.Protocol.Binary.Node.t()
A chat-state (typing) stanza toward to_jid. from is me.lid when to_jid
is a lid jid, else me.id.
@spec parse_update(Amarula.Protocol.Binary.Node.t()) :: {:ok, update()} | {:error, :invalid}
Parse an inbound <presence> or <chatstate> node into an update/0
(Baileys handlePresenceUpdate). Returns {:error, :invalid} for a malformed
node. from/participant are returned as wire jid strings.
@spec presence(presence(), map()) :: {:ok, Amarula.Protocol.Binary.Node.t()} | {:error, :no_name}
Global online/offline presence. me is the auth creds me map (needs :name;
Baileys skips the update without one). Returns {:ok, node} or
{:error, :no_name}.
@spec subscribe(String.t(), String.t()) :: Amarula.Protocol.Binary.Node.t()
A <presence type=subscribe> stanza for to_jid (tcToken omitted).