WardrikTriggers.Trigger (wardrik_triggers v0.1.0-rc.1)

Copy Markdown

A trigger: when to ask an agent, and what. Decoded from a map with string keys, as an agent file writes it.

{:ok, trigger} =
  WardrikTriggers.Trigger.decode(%{
    "name" => "daily",
    "every" => "0 9 * * *",
    "timezone" => "America/Los_Angeles",
    "prompt" => "Write today's update."
  })

See the README for every key.

Summary

Types

How a run went. Matches the protocol's trigger.fired status.

t()

Functions

Decodes a trigger from fields.

Encodes the trigger as a map with string keys. Leaves out unset keys and the default timezone.

Types

status()

@type status() :: :asked | :nothing_new | :busy | :no_agent | :missed | :failed

How a run went. Matches the protocol's trigger.fired status.

t()

@type t() :: %WardrikTriggers.Trigger{
  clock: WardrikTriggers.Clock.t() | nil,
  every: String.t() | nil,
  feeds: [String.t()],
  jitter: non_neg_integer(),
  missed: :run_once | :skip,
  name: String.t(),
  overlap: :skip | :queue,
  prompt: String.t() | nil,
  prompt_file: String.t() | nil,
  timezone: String.t(),
  webhook: %{secret: String.t(), verify: :shared | :standard} | nil
}

Functions

decode(fields, index \\ 1)

@spec decode(map(), pos_integer()) :: {:ok, t()} | {:error, String.t()}

Decodes a trigger from fields.

Without a "name", the name comes from index: trigger-1, trigger-2 and so on. Returns {:error, message} for an unknown key or invalid value.

encode(trigger)

@spec encode(t()) :: map()

Encodes the trigger as a map with string keys. Leaves out unset keys and the default timezone.