AshDispatch.RecipientResolver.Resolver (AshDispatch v0.5.1)
View SourceResolution logic for audience-based recipient lookup.
This module implements the various resolution strategies:
from_context- Extract from event contextfrom_resource- Extract email/name fields from resource (for non-user recipients)query- Query user resource with Ash filterpath- Follow relationship path on resourcecombine- Union of other audiencesresolve- Custom resolver function
Summary
Functions
Resolve recipients for an audience using the DSL configuration.
Follow relationship path on resource.
Query user resource with Ash filter.
Combine multiple audiences (union, deduped by id).
Call custom resolver function.
Extract recipients from context.data.
Extract email/name from resource fields to create a raw recipient map.
Functions
Resolve recipients for an audience using the DSL configuration.
Follow relationship path on resource.
Example
resolve_by_path([:customer, :customer_users, :user], lead)
Query user resource with Ash filter.
Example
resolve_by_query([role: :admin, is_active: true], MyApp.Accounts.User)
Combine multiple audiences (union, deduped by id).
Example
resolve_combined([:owner, :team], resource, context, MyApp.RecipientResolver)
Call custom resolver function.
Examples
# Atom - calls resolver_module.resolve_owner(resource, context)
resolve_custom(:resolve_owner, resource, context, resolver_module)
# Tuple - calls Module.function(resource, context)
resolve_custom({Module, :function}, resource, context, resolver_module)
Extract recipients from context.data.
Examples
# Single key
resolve_from_context(:user, nil, context)
# => extracts context.data.user
# Multiple keys (fallback chain)
resolve_from_context([:user, :assignee], nil, context)
# => tries :user first, falls back to :assignee
# With extract option
resolve_from_context([:meeting, :participants], :user, context)
# => extracts context.data.meeting.participants, then .user from each
Extract email/name from resource fields to create a raw recipient map.
This is a declarative alternative to writing a custom resolver function for non-user recipients (e.g., lead contact emails).
The output map uses field names from your recipient_fields config so that
RecipientExtractor can find them. This ensures compatibility with your
transport configuration.
Options (keyword list)
:email(required) - Field name on the resource containing the email address:name(optional) - Field name on the resource containing the display name:id(optional) - Field name for unique identifier (defaults to:id)
How it works
- Reads your
recipient_fieldsconfig to determine output field names - Extracts values from the specified resource fields
- Creates a recipient map with keys that match your config
For example, with config:
recipient_fields: [email: [identifier: :email, name: :first_name]]And DSL:
from_resource: [email: :contact_email, name: :contact_name]Creates:
%{id: resource.id, email: resource.contact_email, first_name: resource.contact_name}Examples
# Basic usage - just email
resolve_from_resource([email: :contact_email], lead)
# With name
resolve_from_resource([email: :contact_email, name: :contact_name], lead)
# With custom id field
resolve_from_resource([email: :email, name: :name, id: :external_id], record)