Skip to main content
Lua.request tells your code which channel the current turn came from, the raw payload the provider sent on channels that deliver by webhook, the turn’s thread and timezone, and, in a group conversation, who is in it and who is speaking. It is defined in every execution context. Outside a conversation turn, in a job, a webhook, or a trigger, there is no inbound channel: channel is unknown, webhook and conversation are undefined. A model resolver on LuaAgent receives the same LuaRequest as its argument. Verified against lua-cli 3.36.0.

Quick example

A tool condition can hide the tool on channels where it makes no sense.

Properties

request.channel

The channel the current turn arrived on.
Channel is a union of the common names plus string, so comparing against any value type-checks. Keep a default branch. The outbound names on Channels.send differ for two channels: webchat sends to the web widget, and messenger sends to facebook.

request.webhook

The provider’s raw event for the inbound message, when the channel delivers by webhook.
webhook is set when the provider delivered the message by webhook, which is the case for WhatsApp, Messenger, Instagram, Slack, and email, and undefined for the web widget, the REST API, lua test, and every context outside a turn. payload is the provider’s own object: the WhatsApp Cloud API webhook entry, the Slack Events API event, and so on. For email it is a parsed message rather than raw MIME: messageId, inReplyTo, references, subject, from, to, cc, bcc, replyTo, date, and headerLines, where the ids are bare (no angle brackets) and each address is { address, name }. Example

request.threadId, request.timezone, request.userId, request.agentId

The turn’s own coordinates.
threadId is the chat thread the turn runs in; in a group conversation it is the shared room thread, so every participant’s turn carries the same value. timezone is the IANA zone resolved for the turn (Africa/Nairobi), the same one the agent’s date and time instructions use. userId is the end user the turn acts for, and agentId the agent handling it. All four are undefined outside a conversation turn.

request.runtimeContext

Free text the calling surface attached to this turn, for example LuaPop.init({ runtimeContext }) or the runtimeContext field of the chat request body. Present only when the caller supplied it.

request.conversation

The group conversation the turn belongs to, with everyone in it and the person speaking.
Set on a turn in a shared conversation: a room on the desktop, or a Microsoft Teams group chat or team channel the agent has been added to. undefined on a one-to-one chat and in every context outside a turn. Participant names are resolved by the platform, never taken from the message. User.get() still returns the current speaker, so participants is how a tool learns about the other people, for example to act on behalf of a colleague the speaker mentioned. Example

Types

interface
{ request: LuaRequest }, the type of Lua.
interface
{ channel: Channel; webhook?: WebhookRequest; runtimeContext?: string; threadId?: string; timezone?: string; userId?: string; agentId?: string; conversation?: ConversationRef }. Also the argument type of a model resolver, LuaAgentModel = string | ((request: LuaRequest) => string | Promise<string>).
interface
{ payload: any }.
interface
{ id: string; kind: ConversationKind; channel: Channel; externalId?: string; currentSpeakerId?: string; participants: ConversationParticipant[]; participantCount: number; truncated: boolean; agents?: { agentId: string; name?: string }[] }.
interface
{ userId: string; displayName: string; isOwner?: boolean; isCurrentSpeaker?: boolean; channelIdentity?: { provider: 'teams' | 'slack' | 'whatsapp'; externalId: string; email?: string } }.
union
'direct' | 'group'. Today only group is produced; a one-to-one turn has no conversation at all.
union
'web' | 'whatsapp' | 'facebook' | 'instagram' | 'slack' | 'teams' | 'front' | 'messagebird' | 'api' | 'dev' | 'email' | string. The runtime also produces the values listed under request.channel that the union doesn’t spell out.

See also