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

Copy Markdown

Verifies webhook requests against a trigger's secret.

  • :shared - the request presents the secret as Authorization: Bearer SECRET, or as :path_secret.
  • :standard - the request is signed as Standard Webhooks specifies. A signature more than five minutes old fails.

Summary

Types

A request: its raw body, its headers with lowercase names, and an optional path_secret.

Functions

Returns the request's id: its Idempotency-Key, its webhook-id, or a SHA-256 of its body.

Appends the first 32768 characters of the request's body to prompt.

Returns :ok if request verifies with secret, or {:error, reason}.

Types

request()

@type request() :: %{
  :body => String.t(),
  :headers => %{required(String.t()) => String.t()},
  optional(:path_secret) => String.t() | nil
}

A request: its raw body, its headers with lowercase names, and an optional path_secret.

Functions

id(map)

@spec id(request()) :: String.t()

Returns the request's id: its Idempotency-Key, its webhook-id, or a SHA-256 of its body.

prompt(prompt, map)

@spec prompt(String.t(), request()) :: String.t()

Appends the first 32768 characters of the request's body to prompt.

verify(atom, secret, request, now)

@spec verify(:shared | :standard, String.t(), request(), DateTime.t()) ::
  :ok | {:error, String.t()}

Returns :ok if request verifies with secret, or {:error, reason}.