AshDispatch.RecipientResolver.Resolver (AshDispatch v0.5.0)

View Source

Resolution logic for audience-based recipient lookup.

This module implements the various resolution strategies:

  • from_context - Extract from event context
  • from_resource - Extract email/name fields from resource (for non-user recipients)
  • query - Query user resource with Ash filter
  • path - Follow relationship path on resource
  • combine - Union of other audiences
  • resolve - 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).

Extract recipients from context.data.

Extract email/name from resource fields to create a raw recipient map.

Functions

resolve(resolver_module, audience, resource, context)

@spec resolve(module(), atom(), struct() | nil, map()) :: [map()]

Resolve recipients for an audience using the DSL configuration.

resolve_by_path(path, resource)

Follow relationship path on resource.

Example

resolve_by_path([:customer, :customer_users, :user], lead)

resolve_by_query(filter, user_resource)

Query user resource with Ash filter.

Example

resolve_by_query([role: :admin, is_active: true], MyApp.Accounts.User)

resolve_combined(audience_names, resource, context, resolver_module)

Combine multiple audiences (union, deduped by id).

Example

resolve_combined([:owner, :team], resource, context, MyApp.RecipientResolver)

resolve_custom(func_name, resource, context, resolver_module)

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)

resolve_from_context(key, extract, context)

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

resolve_from_resource(field_map, resource)

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

  1. Reads your recipient_fields config to determine output field names
  2. Extracts values from the specified resource fields
  3. 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)