AshDispatch.Resources.DeliveryReceipt (AshDispatch v0.5.1)

View Source

Reference documentation for DeliveryReceipt resources.

Important: This module is a placeholder. Consuming apps must create their own DeliveryReceipt resource using the Base module.

Creating Your DeliveryReceipt Resource

defmodule MyApp.Deliveries.DeliveryReceipt do
  use AshDispatch.Resources.DeliveryReceipt.Base,
    repo: MyApp.Repo,
    domain: MyApp.Deliveries,
    notification_resource: MyApp.Notifications.Notification,
    extensions: [AshTypescript.Resource]

  # Optional: TypeScript type generation
  typescript do
    type_name("DeliveryReceipt")
  end

  # Add your User relationship
  relationships do
    belongs_to :user, MyApp.Accounts.User do
      source_attribute :user_id
      destination_attribute :id
      allow_nil? true
      public? true
    end
  end

  # Optional: Custom policies
  # policies do
  #   policy action_type(:read) do
  #     authorize_if expr(user_id == ^actor(:id))
  #   end
  # end
end

State Machine

Tracks delivery lifecycle:

  • :pending → Initial state when receipt is created
  • :scheduled → Oban job has been enqueued
  • :sending → Actively being delivered
  • :sent → Successfully delivered
  • :failed → Delivery failed (temporary, can retry)
  • :failed_permanent → Delivery failed permanently (no retry)
  • :skipped → Delivery was intentionally skipped

Content Storage

All message content (subject, body, embeds, etc.) is stored in the receipt at creation time. This enables debugging, retry without re-rendering, and historical audit trails.

Configuration

Configure your custom resource in your app:

config :ash_dispatch,
  delivery_receipt_resource: MyApp.Deliveries.DeliveryReceipt

See AshDispatch.Resources.DeliveryReceipt.Base for full documentation.