BaileysEx.Media.Upload (baileys_ex v0.1.0-alpha.9)

Copy Markdown View Source

WhatsApp media connection lookup and CDN upload helpers.

Summary

Functions

Encode a base64 media hash into WhatsApp's URL-safe token form.

Request a fresh media_conn record from WhatsApp's w:m namespace.

Upload an encrypted media file to the WhatsApp CDN.

Types

media_conn()

@type media_conn() :: %{
  auth: String.t(),
  ttl: non_neg_integer(),
  fetch_date: DateTime.t(),
  hosts: [media_host()]
}

media_host()

@type media_host() :: %{
  hostname: String.t(),
  max_content_length_bytes: non_neg_integer() | nil
}

upload_result()

@type upload_result() :: %{
  media_url: String.t() | nil,
  direct_path: String.t() | nil,
  meta_hmac: String.t() | nil,
  ts: integer() | nil,
  fbid: integer() | nil
}

Functions

encode_token(base64)

@spec encode_token(String.t()) :: String.t()

Encode a base64 media hash into WhatsApp's URL-safe token form.

refresh_media_conn(queryable, opts \\ [])

@spec refresh_media_conn(
  GenServer.server() | function(),
  keyword()
) :: {:ok, media_conn()} | {:error, term()}

Request a fresh media_conn record from WhatsApp's w:m namespace.

upload(queryable, encrypted_path, media_type, opts \\ [])

@spec upload(
  GenServer.server() | function(),
  String.t(),
  BaileysEx.Media.Types.media_type(),
  keyword()
) ::
  {:ok, upload_result()} | {:error, term()}

Upload an encrypted media file to the WhatsApp CDN.