Livekitex.Webhook (livekitex v0.1.0)

Webhook validation and processing for LiveKit events.

This module provides functionality to validate and process webhooks sent by LiveKit server. It includes signature validation using HMAC-SHA256 and event parsing.

Summary

Functions

Creates a Plug for webhook validation middleware.

Parses a webhook event from JSON body.

Validates a webhook request and returns the parsed event.

Validates a webhook using Plug.Conn for web frameworks.

Functions

create_plug(api_secret, opts \\ [])

Creates a Plug for webhook validation middleware.

Parameters

  • api_secret - The API secret for signature validation
  • opts - Additional options (optional)

Returns

A Plug that validates webhooks and assigns the event to conn.assigns.webhook_event

parse_webhook_event(body)

Parses a webhook event from JSON body.

Parameters

  • body - JSON string containing the webhook event

Returns

  • {:ok, event} - Successfully parsed event
  • {:error, reason} - Parsing failed

validate_webhook(body, auth_header, api_secret)

Validates a webhook request and returns the parsed event.

Parameters

  • body - The raw webhook body (binary)
  • auth_header - The Authorization header value
  • api_secret - The API secret for signature validation

Returns

  • {:ok, event} - Successfully validated webhook with parsed event
  • {:error, reason} - Validation failed

Examples

iex> Livekitex.Webhook.validate_webhook(body, "Bearer token", "secret")
{:ok, %{event: "room_started", room: %{...}}}

iex> Livekitex.Webhook.validate_webhook(body, "invalid", "secret")
{:error, :invalid_signature}

validate_webhook_conn(conn, api_secret)

Validates a webhook using Plug.Conn for web frameworks.

Parameters

  • conn - Plug.Conn struct
  • api_secret - The API secret for signature validation

Returns

  • {:ok, event} - Successfully validated webhook with parsed event
  • {:error, reason} - Validation failed