KapsoEx.Platform.Webhooks (kapso_ex v0.1.0)

Copy Markdown View Source

Webhook subscriptions.

  • Project webhooks (list/2, create/2, ...) receive project-wide events: connection lifecycle, workflow executions, custom events.
  • Phone number webhooks (*_for_phone_number) receive message and conversation events for one number. kind: "kapso" sends Kapso's payloads; kind: "meta" forwards Meta's payloads unchanged.

Verify deliveries with KapsoEx.Webhook. Event names are listed in Message events and Project webhooks.

Summary

Functions

Creates a project webhook.

Subscribes a URL to a phone number's events. Attributes as in create/2; events is required for kind: "kapso". Only one kind: "meta" webhook is allowed per number.

Deletes a project webhook.

Gets a project webhook.

Lists the project's webhooks (project and phone number scoped), most recent first. Params: kind, page, per_page.

Lists a phone number's webhooks, most recent first.

Sends a test payload to the webhook URL, optionally for a specific event_type.

Updates a project webhook. Attributes as in create/2.

Types

result()

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

Functions

create(client, attrs)

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

Creates a project webhook.

Attributes: url (required), events, secret_key, active, headers, kind, phone_number_id, payload_version, and the buffering settings (buffer_enabled, buffer_window_seconds, max_buffer_size, buffer_events, inactivity_minutes).

Webhooks.create(client, url: "https://example.com/kapso", events: ["whatsapp.phone_number.created"])

create_for_phone_number(client, phone_number_id, attrs)

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

Subscribes a URL to a phone number's events. Attributes as in create/2; events is required for kind: "kapso". Only one kind: "meta" webhook is allowed per number.

Webhooks.create_for_phone_number(client, phone_number_id, %{
  url: "https://example.com/kapso",
  events: ["whatsapp.message.received", "whatsapp.message.failed"],
  secret_key: "..."
})

delete(client, webhook_id)

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

Deletes a project webhook.

delete_for_phone_number(client, phone_number_id, webhook_id)

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

Deletes a phone number webhook.

get(client, webhook_id)

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

Gets a project webhook.

get_for_phone_number(client, phone_number_id, webhook_id)

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

Gets a phone number webhook.

list(client, params \\ [])

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

Lists the project's webhooks (project and phone number scoped), most recent first. Params: kind, page, per_page.

list_for_phone_number(client, phone_number_id, params \\ [])

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

Lists a phone number's webhooks, most recent first.

Params: url_contains, kind, active, created_after, created_before, page, per_page.

test(client, webhook_id, event_type \\ nil)

@spec test(KapsoEx.Client.t(), String.t(), String.t() | nil) :: result()

Sends a test payload to the webhook URL, optionally for a specific event_type.

update(client, webhook_id, attrs)

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

Updates a project webhook. Attributes as in create/2.

update_for_phone_number(client, phone_number_id, webhook_id, attrs)

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

Updates a phone number webhook.