Skip to main content

Overview

LuaWebhook allows you to create HTTP endpoints that can receive events from external services like Stripe, Shopify, GitHub, or any other webhook-enabled platform.
No Conversational Context: Webhooks execute outside of user conversations. You MUST use User.get(userId) with an explicit userId. Always store the user ID in your payment/order metadata.
HTTP webhooks for external integrations. Use with LuaAgent.

Use Cases

Payment Events

Stripe, PayPal webhooks for payment processing

E-commerce Updates

Shopify, WooCommerce order notifications

Git Events

GitHub, GitLab deployment triggers

Custom Integrations

Any service that sends HTTP webhooks

User Access in Webhooks

Webhooks are context-less: They’re triggered by external systems, not user conversations. Always store the Lua user ID in your payment/order metadata so you can notify the right user.

Constructor

new LuaWebhook(config)

Creates a new webhook endpoint.
LuaWebhookConfig
required
Webhook configuration object

Configuration Parameters

Required Fields

string
required
Unique webhook nameFormat: lowercase, hyphens, underscoresExamples: 'payment-webhook', 'order-update-webhook'
function
required
Function that handles incoming webhook eventsSignature: (event: WebhookEvent) => Promise<any>

Optional Fields

string
Webhook description for documentation

WebhookEvent Shape

Every webhook receives a single object with request details:
Destructure the pieces you need inside your handler:
const { query, headers, body, timestamp } = event;
execution is present only when your handler is invoked via a durably-delivered platform event. It is undefined for synchronous requests sent directly to your webhook URL and during local lua test / lua dev runs. See Delivery Semantics.

Complete Examples

Stripe Payment Webhook

Important: Always store the user ID (customerId) in your payment metadata so webhooks can notify the correct user. Example: metadata: { customerId: user.id, orderId: order.id }

Shopify Order Webhook

Customer Identification: Map external customer IDs (Shopify, Stripe) to Lua user IDs. Store this mapping in your order/payment metadata for webhook notifications.

GitHub Deployment Webhook

Generic Webhook Template

Event Subscriptions

Webhooks can subscribe to platform events — currently, message delivery status updates from WhatsApp. When subscribed, your webhook’s execute function receives the event payload automatically.
Event subscriptions currently support WhatsApp status events. Additional channels may emit these events in the future.

Available Event Types

Subscribing via CLI

Event Payload Shape

When an event fires, your webhook receives a WebhookEvent where body contains:

Delivery Semantics

Subscribed platform events are delivered at least once. Each event is durably queued and processed on isolated infrastructure with automatic retries — up to 3 attempts total, a fixed 60-second wait between attempts, retried only on failure. Your handler may therefore run more than once for a single logical event, so keep side effects idempotent. Each invocation receives event.execution:
event.execution is only present for durably-delivered platform events — it is undefined for synchronous direct requests to your webhook URL and during local lua test / lua dev runs. Very large event payloads (over 50,000 characters, which is rare) are delivered without the at-least-once retry guarantee.
Direct requests are unchanged. Requests sent straight to your webhook URL are still handled synchronously with no automatic retries — the caller receives your handler’s return value and applies its own retry policy. At-least-once delivery and event.execution apply only to subscribed platform events.

Example: Track Delivery for Analytics

Using with LuaAgent

Webhooks are added to your agent configuration:

Webhook URLs

After deploying, your webhooks can be called using either identifier:
Notes:
  • agentId is your agent identifier (e.g., agent_abc123)
  • webhookId is the UUID shown when you create the webhook
  • webhook-name is the name you pass to new LuaWebhook
  • You can copy both URLs after pushing: lua push webhook
Examples:
Configure either URL in your external service (Stripe, Shopify, etc.)

Testing Webhooks

Local Testing

Test Payloads

Security Best Practices

Never hardcode secrets
Always validate incoming data
Webhook handlers should return fast (< 5 seconds)

Error Handling

Invoking an Agent from a Webhook

Use Agents.invoke to delegate work to a conversational agent after receiving a webhook event. Pass the user ID from the event payload so the invocation runs in that user’s context (conversation history is stored). If no user ID is available, omit userId and the invocation runs without user identity (no conversation history).

Agents API Reference

Full documentation for Agents.invoke — options, output shape, error handling, and more examples

Common Integrations

Webhook Events:
  • payment_intent.succeeded
  • payment_intent.payment_failed
  • charge.refunded
  • invoice.payment_succeeded
Secret Location: Stripe Dashboard → Developers → Webhooks

LuaAgent

Agent configuration

Agents API

Invoke another agent from a webhook

Jobs API

Queue long-running work

User API

Send notifications

Data API

Store webhook data

See Also