An ntfy action button.
A single struct covers all four action types (:view, :broadcast, :http,
:copy) with the union of their fields; fields not applicable to a type are
nil. Unknown action types are kept as {:unknown, string} rather than
raising, since the server may add types over time.
| Type | Required fields | Optional fields |
|---|---|---|
:view | label, url | clear |
:broadcast | label | intent, extras, clear |
:http | label, url | method, headers, body, clear |
:copy | label, value | clear |
Summary
Functions
Builds an action from a decoded JSON map (the incoming "action" key names
the type).
Encodes an action to the ntfy JSON object shape (the outgoing counterpart of
from_map/1 — fixture maps round-trip exactly).
Encodes an action in ntfy's short header format (§1.5): key=value pairs
joined by ,, with headers and extras maps flattened to
headers.<name>= / extras.<key>= (keys sorted for determinism).
Types
@type t() :: %ExNtfy.Action{ body: String.t() | nil, clear: boolean(), extras: %{optional(String.t()) => String.t()} | nil, headers: %{optional(String.t()) => String.t()} | nil, id: String.t() | nil, intent: String.t() | nil, label: String.t() | nil, method: String.t() | nil, type: type() | nil, url: String.t() | nil, value: String.t() | nil }
@type type() :: :view | :broadcast | :http | :copy | {:unknown, String.t()}
Functions
Builds an action from a decoded JSON map (the incoming "action" key names
the type).
Lenient: missing fields become nil (clear defaults to false), unknown
fields are ignored.
Encodes an action to the ntfy JSON object shape (the outgoing counterpart of
from_map/1 — fixture maps round-trip exactly).
nil fields and a false clear are omitted; plain ntfy-shaped maps pass
through untouched.
Examples
iex> ExNtfy.Action.to_json_map(%ExNtfy.Action{type: :copy, label: "Copy", value: "abc"})
%{"action" => "copy", "label" => "Copy", "value" => "abc"}
Encodes an action in ntfy's short header format (§1.5): key=value pairs
joined by ,, with headers and extras maps flattened to
headers.<name>= / extras.<key>= (keys sorted for determinism).
Values containing ,, ;, or quotes are quoted — double quotes by default,
single quotes when the value itself contains a double quote. clear appears
only when true; id is server-assigned and never emitted.
Examples
iex> ExNtfy.Action.to_short(%ExNtfy.Action{type: :view, label: "Open", url: "https://x.io"})
"action=view, label=Open, url=https://x.io"