Amarula.Profile (amarula v0.1.0)

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. Re-exported from the Amarula facade (Amarula.profile_picture_url/3, Amarula.update_profile_status/2, Amarula.update_profile_picture/3, Amarula.remove_profile_picture/2).

Picture URL privacy token

picture_url/3 implements the common path. WhatsApp can require a per-contact privacy token (tctoken) for other users' pictures; that path is not yet implemented, so fetching some contacts' pictures may return nil. Your own and group pictures are unaffected.

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}.

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}.