Noizu.WhatsApp.Request (Noizu.WhatsApp v0.1.0)

Copy Markdown View Source

Request engine behind every resource module (Graph Cloud API, REST only).

Builds the Req call (Authorization: Bearer <token>), decodes JSON, applies the bounded retry policy, and normalizes failures to %Noizu.WhatsApp.Error{}.

Return shapes

  • {:ok, decoded_body} — 2xx.
  • {:ok, decoded_body, meta} — when the call is made with meta: true.
  • {:error, %Noizu.WhatsApp.Error{}}.

Retry policy

  • 429 — retried with a delay from the Retry-After header or JSON hint, else exponential-ish backoff, clamped to :max_delay_ms.
  • 5xx — retried for idempotent methods only (GET, HEAD, PUT).
  • At most :max_attempts (default 3) total attempts.

Summary

Functions

Percent-encodes one path segment (ids).

Performs one API call. path is relative to the Graph root (the version is inserted automatically, e.g. "12345/messages").

Resolves the sending phone number id from opts[:phone_number_id] or the client, as {:ok, id} or {:error, %Error{tag: :config}}.

Normalizes a recipient or returns a masked validation error.

Types

meta()

@type meta() :: %{status: pos_integer(), attempts: pos_integer()}

method()

@type method() :: :get | :post | :put | :patch | :delete | :head

result()

@type result() ::
  {:ok, term()} | {:ok, term(), meta()} | {:error, Noizu.WhatsApp.Error.t()}

Functions

encode_segment(segment)

@spec encode_segment(term()) :: String.t()

Percent-encodes one path segment (ids).

perform(client, method, path, opts \\ [])

@spec perform(Noizu.WhatsApp.Client.t(), method(), String.t(), keyword()) :: result()

Performs one API call. path is relative to the Graph root (the version is inserted automatically, e.g. "12345/messages").

Options: :json (request body), :params (query; nil values dropped), :form (multipart form), :headers, :meta.

require_phone_number_id(client, opts \\ [])

@spec require_phone_number_id(Noizu.WhatsApp.Client.t(), keyword()) ::
  {:ok, String.t()} | {:error, Noizu.WhatsApp.Error.t()}

Resolves the sending phone number id from opts[:phone_number_id] or the client, as {:ok, id} or {:error, %Error{tag: :config}}.

require_recipient(to)

@spec require_recipient(term()) ::
  {:ok, String.t()} | {:error, Noizu.WhatsApp.Error.t()}

Normalizes a recipient or returns a masked validation error.

require_waba_id(client, opts \\ [])

@spec require_waba_id(Noizu.WhatsApp.Client.t(), keyword()) ::
  {:ok, String.t()} | {:error, Noizu.WhatsApp.Error.t()}

As require_phone_number_id/2 for the WABA id.