# `Accrue.Webhook.Handler`
[🔗](https://github.com/szTheory/accrue/blob/accrue-v0.3.0/lib/accrue/webhook/handler.ex#L1)

Behaviour for webhook event handlers (D2-27).

Implement `handle_event/3` and pattern-match on the event type string:

    defmodule MyApp.BillingHandler do
      use Accrue.Webhook.Handler

      def handle_event("invoice.payment_failed", event, _ctx) do
        MyApp.Slack.notify(event.object_id)
      end
    end

## Registration

Register handlers in your application config:

    config :accrue, webhook_handlers: [MyApp.BillingHandler, MyApp.AnalyticsHandler]

## Dispatch order (D2-30)

1. `Accrue.Webhook.DefaultHandler` runs first (non-disableable)
2. User handlers run sequentially in config list order
3. Each handler is rescue-wrapped -- a crash in one handler does not
   prevent others from running

## Fallthrough

`use Accrue.Webhook.Handler` injects a fallthrough clause that returns
`:ok` for unmatched event types (D2-28). Override this by defining your
own catch-all clause.

# `handle_event`

```elixir
@callback handle_event(
  type :: String.t(),
  event :: Accrue.Webhook.Event.t(),
  ctx :: map()
) ::
  :ok | {:error, term()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
