AshDispatch (AshDispatch v0.5.0)
View SourceEvent-driven notification system for Ash Framework.
AshDispatch provides a declarative way to define and dispatch events across multiple transport types (email, in-app notifications, SMS, webhooks, etc.) with full Ash integration.
Key Components
AshDispatch.Event- Behaviour for defining event modulesAshDispatch.Resource- Ash extension for inline event definitionsAshDispatch.Dispatcher- Main entry point for dispatching eventsAshDispatch.Introspection- DSL introspection utilities
Configuration
config :ash_dispatch,
otp_app: :my_app,
repo: MyApp.Repo,
mailer: MyApp.Mailer,
endpoint: MyAppWeb.Endpoint,
# Must be endpoint-shaped (subscribe/1 + broadcast/3); see
# `AshDispatch.Config.pubsub_module/0` for the contract. Do NOT
# use a bare `Phoenix.PubSub` registered name like `MyApp.PubSub`.
pubsub_module: MyAppWeb.Endpoint,
user_resource: MyApp.Accounts.User,
user_domain: MyApp.AccountsUsage
Inline DSL (in resources)
defmodule MyApp.Orders.ProductOrder do
use Ash.Resource,
extensions: [AshDispatch.Resource]
dispatch do
event :created do
trigger_on [:create]
channels do
channel :email, :user
channel :in_app, :user
end
end
end
endStandalone Event Modules
defmodule MyApp.Events.Orders.Created.Event do
use AshDispatch.Event
dispatch do
id "orders.created"
domain :orders
channels do
channel :email, :user
channel :email, :admin, variant: :admin
end
end
endCode Generation
Run mix ash_dispatch.gen to generate missing files based on DSL definitions:
- Templates for email channels
- Event module stubs for inline events
- TypeScript types for frontend integration