KapsoEx.Platform.Broadcasts (kapso_ex v0.1.0)

Copy Markdown View Source

Send an approved template to many recipients, with per-recipient tracking. See the Broadcasts API guide.

Typical flow:

{:ok, %{"data" => %{"id" => id}}} =
  Broadcasts.create(client, name: "Black Friday", phone_number_id: pnid, whatsapp_template_id: tid)

{:ok, _} =
  Broadcasts.add_recipients(client, id, [
    %{phone_number: "+56961567267", components: [%{type: "body", parameters: [%{type: "text", text: "Ana"}]}]}
  ])

{:ok, _} = Broadcasts.send(client, id)

Kapso paces sends to stay within Meta's throughput limits.

Summary

Functions

Adds up to 1000 recipients to a draft broadcast. Duplicates are skipped.

Cancels a scheduled broadcast and returns it to draft.

Removes every recipient from a draft or scheduled broadcast.

Creates a draft broadcast. Attributes: name, phone_number_id and whatsapp_template_id (all required).

Gets a broadcast with its delivery counters. Poll it to follow progress.

Lists broadcasts, most recent first.

Lists recipients with their delivery status. Params: page, per_page.

Schedules a draft broadcast with recipients. scheduled_at is a DateTime or an ISO 8601 string.

Starts sending now. Sending is asynchronous; poll get/2 for progress.

Changes the status of a broadcast: "stopped" or back to "draft".

Types

result()

@type result() :: {:ok, map()} | {:error, KapsoEx.Error.t()}

Functions

add_recipients(client, broadcast_id, recipients)

@spec add_recipients(KapsoEx.Client.t(), String.t(), [map()]) :: result()

Adds up to 1000 recipients to a draft broadcast. Duplicates are skipped.

Each recipient is a map with phone_number (E.164) or whatsapp_contact_id and, when the template has parameters, components (see KapsoEx.WhatsApp.TemplateComponents).

cancel(client, broadcast_id)

@spec cancel(KapsoEx.Client.t(), String.t()) :: result()

Cancels a scheduled broadcast and returns it to draft.

clear_recipients(client, broadcast_id)

@spec clear_recipients(KapsoEx.Client.t(), String.t()) :: result()

Removes every recipient from a draft or scheduled broadcast.

create(client, attrs)

@spec create(KapsoEx.Client.t(), map() | keyword()) :: result()

Creates a draft broadcast. Attributes: name, phone_number_id and whatsapp_template_id (all required).

get(client, broadcast_id)

@spec get(KapsoEx.Client.t(), String.t()) :: result()

Gets a broadcast with its delivery counters. Poll it to follow progress.

list(client, params \\ [])

@spec list(KapsoEx.Client.t(), map() | keyword()) :: result()

Lists broadcasts, most recent first.

Params: phone_number_id, status, created_after, created_before, page, per_page.

list_recipients(client, broadcast_id, params \\ [])

@spec list_recipients(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()

Lists recipients with their delivery status. Params: page, per_page.

schedule(client, broadcast_id, scheduled_at)

@spec schedule(KapsoEx.Client.t(), String.t(), DateTime.t() | String.t()) :: result()

Schedules a draft broadcast with recipients. scheduled_at is a DateTime or an ISO 8601 string.

send(client, broadcast_id)

@spec send(KapsoEx.Client.t(), String.t()) :: result()

Starts sending now. Sending is asynchronous; poll get/2 for progress.

update_status(client, broadcast_id, status)

@spec update_status(KapsoEx.Client.t(), String.t(), String.t()) :: result()

Changes the status of a broadcast: "stopped" or back to "draft".