Webhooks for Ash Framework — inbound (receive, verify, dedup → domain events) and outbound (sign, deliver, retry, track).

Attach to a resource:

use Ash.Resource,
  extensions: [AshHooks]

webhooks do
  inbound :orders do
    provider MyApp.Webhooks.OrderProvider
    secret {:app_env, [:my_app, :webhook_secret]}
    event_id &MyApp.Webhooks.OrderProvider.event_id/1  # optional: a stable event id from the decoded payload
  end

  outbound :order_paid do
    signing_mode :dual
  end
end

Both halves are independently consumable: inbound-only consumers pull no queue infrastructure (ADR-0004).

Multi-tenant? Declare Ash attribute multitenancy on the four resources (subscription, endpoint, both ledgers) and pass :tenant / ctx[:tenant] to every entry point — every query, write, dedup identity, sweep, and job arg is tenant-scoped, and a tenant-less call against a multitenant resource fails closed with {:error, :tenant_required} before any data access. Single-tenant apps change nothing. The adoption checklist walks the ordered transition (ADR-0011).

webhooks

Webhook declarations — inbound sources and outbound events for this resource.

Nested DSLs

webhooks.inbound

inbound name

Declares an inbound webhook source: a sender whose deliveries this resource receives, verifies, deduplicates, and handles.

Arguments

NameTypeDefaultDocs
nameatomThe source identity stored in the inbound delivery ledger.

Options

NameTypeDefaultDocs
secretanyThe signing-secret source: an {M, f, a} callback, {:app_env, path}, a 0-arity function (app-global), or a 1-arity function (tenant -> {:ok, secret} | {:error, :no_webhook_secret} — resolves the TENANT's secret on multitenant ledgers; arity dispatch on literal fns is unambiguous). A literal binary is rejected at parse time (ADR-0005). Scope: this net catches the secret passed AS the option value; arguments of an MFA source are the consumer's own code.
provideratomThe required module implementing AshHooks.Provider, for example one defined with use AshHooks.Provider, verify: [...]. The source name does not select a module.
body_format:json | :formOpt-in payload decoding for this route. :form decodes application/x-www-form-urlencoded names and values without interpreting bracket notation. Verification still receives the exact raw bytes. When unset, use the provider's decode_payload/1 callback or JSON. The request Content-Type never enables a decoder implicitly.
event_idanyExtractor for the sender's event id from the decoded payload (payload -> {:ok, id} | :error). This explicit extractor takes precedence over the provider's optional event_identity/1. Any result other than {:ok, id} with a binary id uses the raw request-body digest, and an id longer than 255 bytes is stored as its SHA-256. Without an extractor or a provider callback, the raw request-body digest supplies the identity. A provider callback error fails closed rather than falling back to the digest.
previous_secretanyThe ROTATED-OUT signing secret source for this inbound declaration (the same source shapes as secret): during a rotation's overlap window, verification falls back to this key when the current one does not match — both keys verify until you remove the option (the end of your overlap window).
pausedanyThe pause switch source ({m, f, a}, {:app_env, path}, or a 0-arity fn, or tenant-aware 1-arity fn resolving to a boolean): while it resolves true, every request to this source is REFUSED with {:error, :source_paused} before verification or any write; answer 5xx from your controller so the sender retries. Unpause by resolving false again; nothing is lost while paused.
replay_window_secondspos_integerReplay-protection window for providers whose scheme carries a trustworthy timestamp. Providers without timestamps must leave this unset: compilation fails when the provider declares no timestamp header (AshHooks.Provider.timestamp_header/1 returns nil). The window value is passed to the provider's verify_signature/3 in the context map for scheme-specific enforcement. For a configured provider, the window overrides tolerance_seconds.

Introspection

Target: AshHooks.Inbound

webhooks.outbound

outbound name

Declares an outbound webhook event this resource emits to subscribed endpoints — signed (Standard Webhooks canon by default) and delivered with retry/backoff/dead-letter semantics.

Arguments

NameTypeDefaultDocs
nameatomThe outbound event name (e.g. :order_paid).

Options

NameTypeDefaultDocs
signing_mode:legacy | :dual | :standard:standardSignature envelope: :standard (SW canon), :dual (SW canon + legacy envelope for migrating receivers), :legacy (ADR-0002).
subscriptionsatomThe consumer's Subscription resource module (carrying AshHooks.Subscription) this event fans out through — the dispatcher matches its rows against the event type.
deliveriesatomThe consumer's OutboundDelivery resource module (carrying AshHooks.OutboundDelivery) the dispatcher writes the durable per-endpoint rows into.
descriptionString.tThe catalog description of this event type — what it means, when it fires. Read back through AshHooks.Catalog for event pickers and generated docs.
exampleString.tA catalog example payload for this event type — the exact bytes (or a representative JSON document) shown in event pickers and generated docs, and sent by nothing (test sends synthesize their own payloads; wire your own sample through test_send's :payload when you want this one on the wire).
payload_schemaanyThe catalog's payload contract for this event type — a JSON-Schema map, a types module, or any term your docs renderer understands. Data for tooling only; the dispatcher never validates against it.
versionpos_integer1The CURRENT payload version of this event type (default 1). Endpoints without a pin receive this version's bytes.
eventsatomThe consumer's OutboundEvent resource module (carrying AshHooks.OutboundEvent): when set, every dispatch records the event ONCE — id, type, declared version, time, exact payload bytes — whether or not any endpoint was enabled. The log has its own retention (AshHooks.OutboundEvent.prune/2) and answers replays (AshHooks.OutboundEvent.replay/3).
payload_versionsanyThe declared variant builders older pins resolve to: a map of version => {module, function} where f(event) :: {:ok, payload_bytes} | {:error, reason}. An endpoint pinning a version in this map receives that builder's bytes instead of the dispatch payload; a pin on an undeclared version fails that endpoint closed (:unknown_pinned_version) before any row is written.

Introspection

Target: AshHooks.Outbound