Chimeway.Notifier behaviour (chimeway v1.0.0)

Copy Markdown View Source

Behaviour contract for notification definitions.

Delayed fallback channels

delayed_fallback_channels/2 lets notifiers mark outbound channels as delayed fallback candidates. Returned channels must be a subset of channels/2 output and must never include :in_app.

Summary

Types

orchestration_mode()

@type orchestration_mode() :: :immediate | :digest_held

orchestration_resolution()

@type orchestration_resolution() :: %{
  default: orchestration_mode(),
  channels: %{required(String.t()) => orchestration_mode()},
  default_digest_key: String.t() | nil,
  digest_keys: %{required(String.t()) => String.t()},
  source: :default | :notifier | :planner_override
}

workflow_resolution()

@type workflow_resolution() :: %{
  workflow_key: String.t(),
  workflow_version: pos_integer(),
  steps: [workflow_step_resolution()],
  source: :notifier | :planner_override
}

workflow_step_resolution()

@type workflow_step_resolution() :: %{
  step_key: String.t(),
  step_order: pos_integer(),
  channel: String.t(),
  config: map()
}

Callbacks

build(map, map)

@callback build(map(), map()) :: {:ok, map()} | {:error, term()}

channels(map, map)

(optional)
@callback channels(map(), map()) :: {:ok, [atom() | String.t()]} | {:error, term()}

delayed_fallback_channels(map, map)

(optional)
@callback delayed_fallback_channels(map(), map()) ::
  {:ok, [atom() | String.t()]} | {:error, term()}

notification_key()

@callback notification_key() :: String.t()

orchestration(map, map)

(optional)
@callback orchestration(map(), map()) ::
  {:ok, :immediate | :digest | :digest_held | keyword(atom()) | map()}
  | {:error, term()}

recipients(map)

@callback recipients(map()) :: {:ok, [map()]} | {:error, term()}

rendering(map, map)

(optional)
@callback rendering(map(), map()) :: {:ok, map()} | {:error, term()}

version()

@callback version() :: pos_integer()

workflow(map, map)

(optional)
@callback workflow(map(), map()) :: {:ok, map()} | {:error, term()}

Functions

normalize_workflow_declaration(declaration)

@spec normalize_workflow_declaration(map()) ::
  {:ok, workflow_resolution()} | {:error, term()}

persisted_orchestration_override(persisted)

persisted_workflow_override(persisted)

resolve_orchestration(notifier, trigger_params, recipient, override \\ :unset)

@spec resolve_orchestration(module() | nil, map(), map(), term()) ::
  {:ok, orchestration_resolution()} | {:error, term()}

resolve_rendering(notifier, trigger_params, recipient)

@spec resolve_rendering(module(), map(), map()) ::
  {:ok, Chimeway.Rendering.rendering_declaration()} | {:error, term()}

resolve_workflow(notifier, trigger_params, recipient, override \\ :unset)

@spec resolve_workflow(module() | nil, map(), map(), term()) ::
  {:ok, workflow_resolution() | nil} | {:error, term()}

serialize_orchestration(orchestration)

@spec serialize_orchestration(orchestration_resolution()) :: map()

serialize_workflow(workflow)

@spec serialize_workflow(workflow_resolution()) :: map()

validate_module!(module)

@spec validate_module!(module()) :: :ok | {:error, term()}