Codat.Webhooks.Dispatcher (codat v1.0.0)

Copy Markdown View Source

Routes Codat webhook events to multiple handlers based on event type patterns.

Example

defmodule MyApp.CodatWebhooks do
  use Codat.Webhooks.Dispatcher

  on ["invoices.write.successful", "invoices.write.unsuccessful"],
     to: MyApp.InvoiceSyncHandler

  on ~r/^billPayments\.write\./,
     to: MyApp.BillingHandler

  on :all, to: MyApp.AuditLogHandler
end

Use as the :handler in Codat.Webhooks.Plug:

forward "/webhooks/codat", Codat.Webhooks.Plug,
  secret: "whsec_...",
  handler: MyApp.CodatWebhooks

Summary

Functions

Registers a route mapping event type(s) to a handler module.

Functions

on(pattern, list)

(macro)

Registers a route mapping event type(s) to a handler module.

  • String — exact match
  • List — match any element
  • Regex — pattern match
  • :all — catch-all fallback