# `WardrikTriggers.Trigger`

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.

# `status`

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

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

# `t`

```elixir
@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
}
```

# `decode`

```elixir
@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`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
