AshDispatch.Channel (AshDispatch v0.5.0)
View SourceRepresents a delivery channel for an event.
A channel specifies:
- Transport - How to deliver (email, in_app, discord, etc.)
- Audience - Who receives (:user, :admin, custom)
- Time - When to deliver (immediate, delayed, scheduled)
- Policy - Delivery policy (:always, :skip_if_read)
- Variant - Template variant (e.g., :admin for admin-specific templates)
Examples
%Channel{
transport: :email,
audience: :user,
time: {:in, 300}, # Delay 5 minutes
policy: :skip_if_read
}
%Channel{
transport: :discord,
audience: :admin,
time: :immediate,
opts: %{webhook_url: "https://..."}
}
Summary
Functions
Calculates delay in seconds from time specification.
Helper function to create a channel struct. Used in DSL and event modules for cleaner syntax.
Checks if a channel matches given transport and/or audience filters.
Creates a new channel.
Normalizes time specification to internal format.
Types
@type audience() :: :user | :admin | atom()
@type policy() :: :always | :skip_if_read | {:gate, function()}
@type t() :: %AshDispatch.Channel{ audience: audience(), content: map(), deduplicate_group: atom() | nil, exclude_actor: boolean(), load: [atom() | {atom(), any()}], locale: String.t() | nil, locale_from: atom() | nil, locales: [String.t()], metadata: map(), optional: boolean(), opts: map(), policy: policy(), time: time(), transport: transport(), variant: variant(), webhook_url: String.t() | nil }
@type time() :: :immediate | {:in, non_neg_integer()} | {:at, DateTime.t()} | {:window, map()}
@type transport() :: :email | :in_app | :discord | :sms | :slack | :webhook | atom()
@type variant() :: atom() | nil
Functions
Calculates delay in seconds from time specification.
Examples
iex> Channel.calculate_delay(%Channel{time: {:in, 300}})
300
iex> Channel.calculate_delay(%Channel{time: :immediate})
0
Helper function to create a channel struct. Used in DSL and event modules for cleaner syntax.
Examples
def channels(_ctx) do
[
channel(:in_app, :user),
channel(:email, :user, time: 5.minutes(), skip_if_read: true)
]
end
Checks if a channel matches given transport and/or audience filters.
Examples
iex> channel = %Channel{transport: :in_app, audience: :user}
iex> Channel.matches?(channel, transport: :in_app)
true
iex> Channel.matches?(channel, transport: :email)
false
iex> Channel.matches?(channel, transport: :in_app, audience: :user)
true
Creates a new channel.
Examples
iex> Channel.new(:email, :user)
%Channel{transport: :email, audience: :user, time: {:in, 0}}
iex> Channel.new(:email, :user, time: 5.minutes(), skip_if_read: true)
%Channel{
transport: :email,
audience: :user,
time: {:in, 300},
policy: :skip_if_read
}
Normalizes time specification to internal format.
Examples
iex> Channel.normalize_time(:immediate)
{:in, 0}
iex> Channel.normalize_time(300)
{:in, 300}
iex> Channel.normalize_time({:in, 300})
{:in, 300}