Tayori.Webhooks (Tayori v0.1.0)

Copy Markdown View Source

Tells other places of each entry when it is published: the :webhooks feature. The admin adds them in Settings:

  • a webhook - a POST of the entry as JSON, signed with its secret (x-tayori-signature: sha256=<hex HMAC of the body>);
  • Slack - a message to an incoming webhook URL;
  • Discord - a message to a channel webhook URL.

Their URLs and secrets are kept encrypted, as the AI key is (a :vault or the :secret_key_base of Tayori.Config). A failed delivery is tried again (Tayori.Jobs), unless the place refused it for good.

A webhook gets every entry, for everyone or not; Slack and Discord get the entries for everyone, which are public.

Summary

Types

A place told of the entries.

Functions

Adds a place: a kind, a name, an https URL and, for a webhook, a secret to sign with (one is made when none is given). Returns the secret.

The kinds of places.

The places, without their secrets: %{"id", "kind", "name", "host"}, where host shows where it goes without the secret part of the URL.

Removes a place.

Sends a test message to a place, and returns how it went.

Types

hook()

@type hook() :: %{required(String.t()) => String.t()}

A place told of the entries.

Functions

add(kind, name, url, secret \\ nil)

@spec add(String.t(), String.t(), String.t(), String.t() | nil) ::
  {:ok, String.t() | nil} | {:error, atom()}

Adds a place: a kind, a name, an https URL and, for a webhook, a secret to sign with (one is made when none is given). Returns the secret.

kinds()

@spec kinds() :: [String.t()]

The kinds of places.

list()

@spec list() :: [map()]

The places, without their secrets: %{"id", "kind", "name", "host"}, where host shows where it goes without the secret part of the URL.

remove(id)

@spec remove(String.t()) :: :ok

Removes a place.

test(id)

@spec test(String.t()) :: :ok | {:error, term()}

Sends a test message to a place, and returns how it went.