Amarula.Profile (amarula v0.5.7)

Copy Markdown View Source

Profile reads and writes: fetch a profile-picture URL, set/remove your (or a group's) picture, and set your status/bio. The consumer-facing half of Baileys' profilePictureUrl / updateProfilePicture / removeProfilePicture / updateProfileStatus.

Each function builds an IQ via Amarula.Protocol.Profile.Ops, sends it through Amarula.Connection.query_iq/3, and parses the reply. Call them on this module: picture_url/3, update_picture/3, remove_picture/2, update_status/2.

Picture URL privacy token

WhatsApp requires a per-contact privacy token (tctoken) to show you another user's picture. picture_url/3 attaches one automatically when we hold it — never for your own account (with a token attached the server simply never replies) and never for a group. With no token held the query still goes out unadorned, so a contact you have not yet exchanged trust with can still return nil; see Amarula.Protocol.Signal.TcTokenStore for how tokens are earned.

Summary

Functions

Fetch the profile-picture URL for jid (a user or group). type is :preview (small, default) or :image (full). Returns {:ok, url}, {:ok, nil} when there is no picture (or it is not visible to you), or {:error, reason}.

Remove your own (or a group's) profile picture. Returns :ok or {:error, reason}.

Set your own profile picture (or a group's, if jid is a group you administer) from already-encoded JPEG bytes. WhatsApp expects a small square JPEG; the caller must size it (Amarula does not resize — see the module note). Returns :ok or {:error, reason}.

Set your own profile status/bio text. Returns :ok or {:error, reason}.

Types

conn()

@type conn() :: GenServer.server()

Functions

picture_url(conn, jid, type \\ :preview)

@spec picture_url(
  conn(),
  String.t() | Amarula.Address.t(),
  Amarula.Protocol.Profile.Ops.pic_type()
) ::
  {:ok, String.t() | nil} | {:error, term()}

Fetch the profile-picture URL for jid (a user or group). type is :preview (small, default) or :image (full). Returns {:ok, url}, {:ok, nil} when there is no picture (or it is not visible to you), or {:error, reason}.

A held trusted-contact token is attached automatically — see the module note.

remove_picture(conn, jid)

@spec remove_picture(conn(), String.t() | Amarula.Address.t()) ::
  :ok | {:error, term()}

Remove your own (or a group's) profile picture. Returns :ok or {:error, reason}.

update_picture(conn, jid, jpeg_bytes)

@spec update_picture(conn(), String.t() | Amarula.Address.t(), binary()) ::
  :ok | {:error, term()}

Set your own profile picture (or a group's, if jid is a group you administer) from already-encoded JPEG bytes. WhatsApp expects a small square JPEG; the caller must size it (Amarula does not resize — see the module note). Returns :ok or {:error, reason}.

update_status(conn, status)

@spec update_status(conn(), String.t()) :: :ok | {:error, term()}

Set your own profile status/bio text. Returns :ok or {:error, reason}.