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
Creates a Plug for webhook validation middleware.
Parameters
api_secret
- The API secret for signature validationopts
- Additional options (optional)
Returns
A Plug that validates webhooks and assigns the event to conn.assigns.webhook_event
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
Validates a webhook request and returns the parsed event.
Parameters
body
- The raw webhook body (binary)auth_header
- The Authorization header valueapi_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}
Validates a webhook using Plug.Conn for web frameworks.
Parameters
conn
- Plug.Conn structapi_secret
- The API secret for signature validation
Returns
{:ok, event}
- Successfully validated webhook with parsed event{:error, reason}
- Validation failed