Webhooks are HTTP endpoints that allow external services to send events to your agent. When something happens in an external system (like a payment completing or an order shipping), that system can notify your agent in real-time.
Think of it as:
A phone number for your agent - external services can “call” it when events happen
No Conversational Context: Webhooks execute outside of user conversations. You MUST provide a userId when calling User.get(userId) to notify specific users. Store user IDs in your payment/order metadata.
New in v3.0.0: Built-in webhook support for seamless external integrations.
import { LuaWebhook, User } from 'lua-cli';const paymentWebhook = new LuaWebhook({ name: 'payment-webhook', description: 'Handle Stripe payment events', execute: async (event) => { const { body } = event; if (body?.type === 'payment_intent.succeeded') { // ⚠️ Webhooks have NO conversational context // You MUST provide userId to User.get() // Get user ID from payment metadata const customerId = body.data?.object?.metadata?.customerId; if (!customerId) { console.error('No customerId in payment metadata'); return { received: true, error: 'No customer ID' }; } // Retrieve specific user by ID const user = await User.get(customerId); // Send payment confirmation to that user await user.send([{ type: 'text', text: `✅ Payment confirmed! Amount: ${body.data.object.amount} ${body.data.object.currency.toUpperCase()}` }]); } return { received: true }; }});
Critical: Webhooks execute outside conversational context. User.get() REQUIRES a userId parameter. Always store the user ID in your payment/order metadata when creating transactions.