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
endRegistration
Register handlers in your application config:
config :accrue, webhook_handlers: [MyApp.BillingHandler, MyApp.AnalyticsHandler]Dispatch order (D2-30)
Accrue.Webhook.DefaultHandlerruns first (non-disableable)- User handlers run sequentially in config list order
- 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.
Summary
Callbacks
@callback handle_event( type :: String.t(), event :: Accrue.Webhook.Event.t(), ctx :: map() ) :: :ok | {:error, term()}