Amarula.Content.Media (amarula v0.3.0)

View Source

A received media attachment (content of a %Amarula.Msg{type: :media}) — an inbound image / video / audio / document / sticker. A plain snake_case struct, not the raw protobuf. Pass it (or the whole %Amarula.Msg{}) to Amarula.download_media/1 to fetch and decrypt the bytes — no live connection needed; the keys ride in this struct.

Fields

  • :kind:image | :video | :audio | :document | :sticker.

  • :mimetype — the content type (e.g. "image/jpeg", "video/mp4", "image/webp" for a sticker). Use this for the file extension / <img> vs <video>, not :kind — WhatsApp sends webp stickers, mp4 "gifs", etc.
  • :caption — text shown with the media (nil if none).
  • :file_length — size in bytes (nil if absent).
  • :width / :height — pixel dimensions for image/video/sticker (nil otherwise).
  • :seconds — duration for audio/video (nil otherwise).
  • :file_name — original file name for documents (nil otherwise).

The remaining fields (:url, :direct_path, :media_key, :file_sha256, :file_enc_sha256) are the CDN locator + decryption material used by download_media; you rarely read them directly.

Summary

Functions

Normalize a raw media proto (%Proto.Message.ImageMessage{} etc.) into a %Amarula.Content.Media{}. kind says which proto it is — several distinct media protos map to this one struct, so the kind can't be recovered from the proto alone. Snake-cases the camelCase fields and surfaces the type-relevant metadata; missing fields are nil.

Types

kind()

@type kind() :: :image | :video | :audio | :document | :sticker

t()

@type t() :: %Amarula.Content.Media{
  caption: String.t() | nil,
  direct_path: String.t() | nil,
  file_enc_sha256: binary() | nil,
  file_length: non_neg_integer() | nil,
  file_name: String.t() | nil,
  file_sha256: binary() | nil,
  height: non_neg_integer() | nil,
  kind: kind(),
  media_key: binary() | nil,
  mimetype: String.t() | nil,
  seconds: non_neg_integer() | nil,
  url: String.t() | nil,
  width: non_neg_integer() | nil
}

Functions

from_proto(kind, m)

@spec from_proto(
  kind(),
  struct()
) :: t()

Normalize a raw media proto (%Proto.Message.ImageMessage{} etc.) into a %Amarula.Content.Media{}. kind says which proto it is — several distinct media protos map to this one struct, so the kind can't be recovered from the proto alone. Snake-cases the camelCase fields and surfaces the type-relevant metadata; missing fields are nil.