Overview
TheLua API provides access to request-level runtime information. Use it in your tools, tool conditions, preprocessors, and postprocessors to access context about the current request.
Import
Availability
TheLua API is available in:
Lua.request
Therequest object contains information about the current request context.
channel
The channel through which the current request originated.Channel
webhook
The webhook object contains information about the incoming webhook request from channel integrations. This provides access to the original data sent by the channel provider (WhatsApp, Slack, Teams, etc.).{ payload: any } | undefined
The webhook object is only available when the request originated from a webhook-based channel. For direct API calls or the web chat widget, this will be undefined.
webhook.payload
The raw, unmodified webhook payload from the channel provider. Available for channels:whatsapp- Full WhatsApp Cloud API webhook payloadslack- Slack Events API payloadteams- Microsoft Teams activity objectfront- Front webhook bodyfacebook- Facebook Messenger webhook eventinstagram- Instagram Messaging webhook eventmessagebird- MessageBird webhook bodyemail- JMAP-aligned parsed email (headers + envelope; not raw MIME — see note below)
The
email channel’s payload differs from JSON-over-HTTP channels (WhatsApp, Slack, etc.). Email arrives over SMTP as RFC 5322 MIME — there is no JSON envelope from a provider to forward. Lua parses the message and exposes it as a JMAP-aligned object: typed common headers plus a headerLines array preserving the full RFC 5322 header order.If your email channel is backed by an AgentMail inbox,
webhook.payload follows AgentMail’s native event shape (message_id, thread_id, inbox_id, …) rather than the JMAP shape above. Branch on the presence of messageId (Lua-native) vs message_id (AgentMail) until the shapes are normalized.Complete Examples
Conditional Tool Availability
Make a tool available only on certain channels:Channel-Aware Tool Logic
Adjust tool behavior based on channel:Preprocessor with Channel Context
Use channel in preprocessors:Postprocessor with Channel-Specific Formatting
Format responses based on channel:Future Expansion
TheLua API will be expanded to include additional runtime information, such as:
- User profile data
- Session information
- More request metadata
This API is designed to grow. Check back for new properties as they become available.
Best Practices
✅ Import from lua-cli
✅ Import from lua-cli
Always import the
Lua API from lua-cli:✅ Handle Unknown Channels
✅ Handle Unknown Channels
The channel type includes
unknown for unrecognized values:✅ Keep Channel Logic Simple
✅ Keep Channel Logic Simple
Use channel for minor adjustments, not completely different flows:
✅ Use Tool Conditions for Availability
✅ Use Tool Conditions for Availability
For channel-specific tools, use the
condition function:✅ Check webhook Before Use
✅ Check webhook Before Use
Always check if webhook exists before accessing it:
✅ Combine Channel Check with webhook
✅ Combine Channel Check with webhook
For channel-specific webhook handling, always check both:
Related
Skills & Tools
Learn about creating tools with conditions
Preprocessors
Intercept and modify incoming messages
Postprocessors
Transform agent responses
Channels
Overview of available channels

