WhatsApp.WebhookPlug.Handler behaviour (WhatsApp SDK v0.1.0)

Copy Markdown View Source

Behaviour for WhatsApp webhook event handlers.

Implement this behaviour to process incoming webhook events from the WhatsApp Business API. Each event corresponds to a "value" entry from the webhook payload's "changes" list.

Example

defmodule MyApp.WhatsAppHandler do
  @behaviour WhatsApp.WebhookPlug.Handler

  @impl true
  def handle_event(%{"messages" => messages} = _event) do
    Enum.each(messages, &process_message/1)
    :ok
  end

  def handle_event(_event), do: :ok

  defp process_message(message) do
    # Handle the message
    IO.inspect(message, label: "Received WhatsApp message")
  end
end

Summary

Callbacks

Called for each webhook event received from the WhatsApp Business API.

Callbacks

handle_event(event)

@callback handle_event(event :: map()) :: :ok | {:error, term()}

Called for each webhook event received from the WhatsApp Business API.

The event map is the "value" from each change entry in the webhook payload. It typically contains keys like "messages", "statuses", "contacts", "metadata", etc.

Return :ok on success or {:error, reason} on failure. Note that returning an error does not change the HTTP response sent to Meta (which is always 200 to acknowledge receipt).