Anu.Client (Anu v0.2.0)

Copy Markdown View Source

An explicit client holding the credentials and settings used to deliver messages and call anu_cloud.

Anu never reads application env for delivery and never starts its own Finch instance: you bring a Finch name (started in your own supervision tree) and the credentials for each WhatsApp phone number / WABA.

Build one client per phone number / WABA to run multiple numbers or multiple access tokens in the same BEAM node:

# In your application supervision tree:
#   {Finch, name: MyApp.Finch}

support = Anu.Client.new(finch: MyApp.Finch, access_token: "EAAG...", phone_number_id: "111")
sales   = Anu.Client.new(finch: MyApp.Finch, access_token: "EAAG...", phone_number_id: "222")

Anu.Message.new("+5511...")
|> Anu.Message.text("hi")
|> Anu.deliver(support)

Credentials (:access_token, :phone_number_id, :cloud_api_key) may be nil until use; adapters raise at delivery time when they are missing.

Summary

Functions

Builds a client from the given attributes.

Types

t()

@type t() :: %Anu.Client{
  access_token: String.t() | nil,
  adapter: module(),
  api_version: String.t(),
  cloud_api_key: String.t() | nil,
  cloud_url: String.t(),
  finch: Finch.name(),
  phone_number_id: String.t() | nil
}

Functions

new(attrs)

@spec new(keyword() | map()) :: t()

Builds a client from the given attributes.

:finch is required. Library defaults are used for anything not given. Accepts a keyword list or a map. Unknown keys raise KeyError via struct!/2.

Examples

iex> Anu.Client.new(finch: MyApp.Finch, access_token: "EAAG...", phone_number_id: "111")
%Anu.Client{finch: MyApp.Finch, access_token: "EAAG...", phone_number_id: "111"}