You can use Hooks to intercept and modify messages, perform logging, integrate with external systems, and more.
Hooks vs. Actions / Execute Code
Hooks let you use custom code with your bot, just like Actions and Execute Code Cards. The key difference is when the code runs: - Actions and Execute Code Cards run at some point in your Workflow. - Hooks run during specific stages of the bot’s operation cycle
Overview
When you add a new Hook, it defines a function that executes every time your bot reaches a certain cycle of its operation.
All Hooks take an event parameter, which contains information about the event that triggered the Hook.
Some Hook types take additional parameters—check out the Hook guides on this page for more information.
Add a Hook
Navigate to the Hooks section in the Studio’s left navigation bar.
Select Create Hook, then choose a type for the Hook.
Choose a name for the Hook. Done!
Hook types
Here’s a breakdown of each type of Hook:
Before Incoming
This Hook type executes its code before your bot processes an incoming event.
Parameters:
eventIncomingEvent
Information about the last incoming event in your bot's execution.
botIdstring
The ID of the bot that experienced the event.
conversationId?string
The ID of the conversation that the event took place in.
createdOnDate
The date and time when the event was created (in ISO 8601 format).
directionEventDirection
The direction of the event, indicating whether the event was received by
the bot or sent from the bot. - `'incoming'`: The event originated from
the user and was received by the bot. - `'outgoing'`: The event was
generated by the bot and sent to the user.
The ID of the conversation associated with this Trigger.
eventName?string
The name of the event that the Trigger sent.
flowIdstring
The ID of the Workflow containing the Trigger.
integration?string
The integration associated with the Trigger.
nodeIdstring
The ID of the Node that contains the Trigger.
userId?string
The ID of the user associated with this Trigger.
typestring
The type of the event.
userId?string
The user ID associated with this event.
After Incoming
This Hook type executes its code after the incoming message has been processed, but before the bot has responded.
Parameters:
eventIncomingEvent
Information about the last incoming event in your bot's execution.
botIdstring
The ID of the bot that experienced the event.
conversationId?string
The ID of the conversation that the event took place in.
createdOnDate
The date and time when the event was created (in ISO 8601 format).
directionEventDirection
The direction of the event, indicating whether the event was received by
the bot or sent from the bot. - `'incoming'`: The event originated from
the user and was received by the bot. - `'outgoing'`: The event was
generated by the bot and sent to the user.
The ID of the conversation associated with this Trigger.
eventName?string
The name of the event that the Trigger sent.
flowIdstring
The ID of the Workflow containing the Trigger.
integration?string
The integration associated with the Trigger.
nodeIdstring
The ID of the Node that contains the Trigger.
userId?string
The ID of the user associated with this Trigger.
typestring
The type of the event.
userId?string
The user ID associated with this event.
Before Outgoing
This Hook type executes its code before the bot’s reply is sent to the user.
Parameters:
eventIncomingEvent
Information about the last incoming event in your bot's execution.
botIdstring
The ID of the bot that experienced the event.
conversationId?string
The ID of the conversation that the event took place in.
createdOnDate
The date and time when the event was created (in ISO 8601 format).
directionEventDirection
The direction of the event, indicating whether the event was received by
the bot or sent from the bot. - `'incoming'`: The event originated from
the user and was received by the bot. - `'outgoing'`: The event was
generated by the bot and sent to the user.
The ID of the conversation associated with this Trigger.
eventName?string
The name of the event that the Trigger sent.
flowIdstring
The ID of the Workflow containing the Trigger.
integration?string
The integration associated with the Trigger.
nodeIdstring
The ID of the Node that contains the Trigger.
userId?string
The ID of the user associated with this Trigger.
typestring
The type of the event.
userId?string
The user ID associated with this event.
outgoingEvent?IO.OutgoingEvent
The message sent by the bot
Before LLMz Execution
This Hook type executes its code before the LLMz engine begins its execution.
Parameters:
eventIncomingEvent
Information about the last incoming event in your bot's execution.
botIdstring
The ID of the bot that experienced the event.
conversationId?string
The ID of the conversation that the event took place in.
createdOnDate
The date and time when the event was created (in ISO 8601 format).
directionEventDirection
The direction of the event, indicating whether the event was received by
the bot or sent from the bot. - `'incoming'`: The event originated from
the user and was received by the bot. - `'outgoing'`: The event was
generated by the bot and sent to the user.
The ID of the conversation associated with this Trigger.
eventName?string
The name of the event that the Trigger sent.
flowIdstring
The ID of the Workflow containing the Trigger.
integration?string
The integration associated with the Trigger.
nodeIdstring
The ID of the Node that contains the Trigger.
userId?string
The ID of the user associated with this Trigger.
typestring
The type of the event.
userId?string
The user ID associated with this event.
context?LLMZ.CreateContext
The current context provided to the LLMz
id?string
The unique identifier of the LLMz execution, prefixed with llmz_
version?any
The version of the LLMz engine or context
instructions?string
Optional instructions provided to guide the LLMz execution
objects?LLMZ.Obj[]
A list of objects relevant to the LLMz context
tools?LLMZ.Tool[]
A list of tools available for the LLMz engine to use
loop?number
The current loop count of the LLMz iteration process
temperature?number
The temperature setting used for the LLM model
model?string
The name or identifier of the LLM model being used.
transcript?OAI.Message[]
The conversation transcript, including all prior messages in the current context
location?LLMZ.Location
The current location within the bot’s logic
After LLMz Execution
This Hook type executes its code after the LLMz engine finishes its execution.
Parameters:
eventIncomingEvent
Information about the last incoming event in your bot's execution.
botIdstring
The ID of the bot that experienced the event.
conversationId?string
The ID of the conversation that the event took place in.
createdOnDate
The date and time when the event was created (in ISO 8601 format).
directionEventDirection
The direction of the event, indicating whether the event was received by
the bot or sent from the bot. - `'incoming'`: The event originated from
the user and was received by the bot. - `'outgoing'`: The event was
generated by the bot and sent to the user.
The ID of the conversation associated with this Trigger.
eventName?string
The name of the event that the Trigger sent.
flowIdstring
The ID of the Workflow containing the Trigger.
integration?string
The integration associated with the Trigger.
nodeIdstring
The ID of the Node that contains the Trigger.
userId?string
The ID of the user associated with this Trigger.
typestring
The type of the event.
userId?string
The user ID associated with this event.
execution?LLMZ.ExecutionResult
The result of the execution
After LLMz iteration
Depending on how demanding the task is, the LLMz may loop through multiple iterations before finishing its execution. This Hook type executes its code after each iteration.
Parameters:
eventIncomingEvent
Information about the last incoming event in your bot's execution.
botIdstring
The ID of the bot that experienced the event.
conversationId?string
The ID of the conversation that the event took place in.
createdOnDate
The date and time when the event was created (in ISO 8601 format).
directionEventDirection
The direction of the event, indicating whether the event was received by
the bot or sent from the bot. - `'incoming'`: The event originated from
the user and was received by the bot. - `'outgoing'`: The event was
generated by the bot and sent to the user.
The ID of the conversation associated with this Trigger.
eventName?string
The name of the event that the Trigger sent.
flowIdstring
The ID of the Workflow containing the Trigger.
integration?string
The integration associated with the Trigger.
nodeIdstring
The ID of the Node that contains the Trigger.
userId?string
The ID of the user associated with this Trigger.
typestring
The type of the event.
userId?string
The user ID associated with this event.
iteration?LLMZ.IterationResult
The result of the iteration
After Conversation End
This Hook type executes after the conversation has explicitly ended (transitioned to an End Node)
Parameters:
eventIncomingEvent
Information about the last incoming event in your bot's execution.
botIdstring
The ID of the bot that experienced the event.
conversationId?string
The ID of the conversation that the event took place in.
createdOnDate
The date and time when the event was created (in ISO 8601 format).
directionEventDirection
The direction of the event, indicating whether the event was received by
the bot or sent from the bot. - `'incoming'`: The event originated from
the user and was received by the bot. - `'outgoing'`: The event was
generated by the bot and sent to the user.
Information about the last incoming event in your bot's execution.
botIdstring
The ID of the bot that experienced the event.
conversationId?string
The ID of the conversation that the event took place in.
createdOnDate
The date and time when the event was created (in ISO 8601 format).
directionEventDirection
The direction of the event, indicating whether the event was received by
the bot or sent from the bot. - `'incoming'`: The event originated from
the user and was received by the bot. - `'outgoing'`: The event was
generated by the bot and sent to the user.