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 anevent 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 incomingevent.
Parameters:
IncomingEvent
Information about the last incoming event in your bot’s execution.
Show child attributes
Show child attributes
string
required
The ID of the bot that experienced the event.
string
The ID of the conversation that the event took place in.
EventDirection
required
The direction of the event, indicating whether the event was received by the bot or sent from the bot.Possible values:
'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.
string
required
The unique identifier for the event.
string
The integration that the event occurred on.
object
Information about Knowledge Bases queried for the event.
Show child attributes
Show child attributes
Studio.KnowledgeBase.KB[]
required
Array of Knowledge Bases queried for the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
Studio.KnowledgeBase.ContentResult[]
Array of Knowledge Base results consulted for this event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
string
The unique identifier for the current event’s message.
object
required
The payload for the current event.
string
required
A representation of the event in plain text. If the event is text message, this property will contain the message itself.
EventState
required
Data related to the state of the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
EventTags
DM.Trigger
The Trigger that sent the event.
Show child attributes
Show child attributes
string
The ID of the conversation associated with this Trigger.
string
The name of the event that the Trigger sent.
string
required
The ID of the Workflow containing the Trigger.
string
The integration associated with the Trigger.
string
required
The ID of the Node that contains the Trigger.
string
The ID of the user associated with this Trigger.
string
required
The type of the event.
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:IncomingEvent
Information about the last incoming event in your bot’s execution.
Show child attributes
Show child attributes
string
required
The ID of the bot that experienced the event.
string
The ID of the conversation that the event took place in.
EventDirection
required
The direction of the event, indicating whether the event was received by the bot or sent from the bot.Possible values:
'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.
string
required
The unique identifier for the event.
string
The integration that the event occurred on.
object
Information about Knowledge Bases queried for the event.
Show child attributes
Show child attributes
Studio.KnowledgeBase.KB[]
required
Array of Knowledge Bases queried for the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
Studio.KnowledgeBase.ContentResult[]
Array of Knowledge Base results consulted for this event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
string
The unique identifier for the current event’s message.
object
required
The payload for the current event.
string
required
A representation of the event in plain text. If the event is text message, this property will contain the message itself.
EventState
required
Data related to the state of the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
EventTags
DM.Trigger
The Trigger that sent the event.
Show child attributes
Show child attributes
string
The ID of the conversation associated with this Trigger.
string
The name of the event that the Trigger sent.
string
required
The ID of the Workflow containing the Trigger.
string
The integration associated with the Trigger.
string
required
The ID of the Node that contains the Trigger.
string
The ID of the user associated with this Trigger.
string
required
The type of the event.
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:IncomingEvent
Information about the last incoming event in your bot’s execution.
Show child attributes
Show child attributes
string
required
The ID of the bot that experienced the event.
string
The ID of the conversation that the event took place in.
EventDirection
required
The direction of the event, indicating whether the event was received by the bot or sent from the bot.Possible values:
'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.
string
required
The unique identifier for the event.
string
The integration that the event occurred on.
object
Information about Knowledge Bases queried for the event.
Show child attributes
Show child attributes
Studio.KnowledgeBase.KB[]
required
Array of Knowledge Bases queried for the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
Studio.KnowledgeBase.ContentResult[]
Array of Knowledge Base results consulted for this event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
string
The unique identifier for the current event’s message.
object
required
The payload for the current event.
string
required
A representation of the event in plain text. If the event is text message, this property will contain the message itself.
EventState
required
Data related to the state of the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
EventTags
DM.Trigger
The Trigger that sent the event.
Show child attributes
Show child attributes
string
The ID of the conversation associated with this Trigger.
string
The name of the event that the Trigger sent.
string
required
The ID of the Workflow containing the Trigger.
string
The integration associated with the Trigger.
string
required
The ID of the Node that contains the Trigger.
string
The ID of the user associated with this Trigger.
string
required
The type of the event.
string
The user ID associated with this event.
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:IncomingEvent
Information about the last incoming event in your bot’s execution.
Show child attributes
Show child attributes
string
required
The ID of the bot that experienced the event.
string
The ID of the conversation that the event took place in.
EventDirection
required
The direction of the event, indicating whether the event was received by the bot or sent from the bot.Possible values:
'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.
string
required
The unique identifier for the event.
string
The integration that the event occurred on.
object
Information about Knowledge Bases queried for the event.
Show child attributes
Show child attributes
Studio.KnowledgeBase.KB[]
required
Array of Knowledge Bases queried for the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
Studio.KnowledgeBase.ContentResult[]
Array of Knowledge Base results consulted for this event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
string
The unique identifier for the current event’s message.
object
required
The payload for the current event.
string
required
A representation of the event in plain text. If the event is text message, this property will contain the message itself.
EventState
required
Data related to the state of the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
EventTags
DM.Trigger
The Trigger that sent the event.
Show child attributes
Show child attributes
string
The ID of the conversation associated with this Trigger.
string
The name of the event that the Trigger sent.
string
required
The ID of the Workflow containing the Trigger.
string
The integration associated with the Trigger.
string
required
The ID of the Node that contains the Trigger.
string
The ID of the user associated with this Trigger.
string
required
The type of the event.
string
The user ID associated with this event.
LLMZ.CreateContext
The current context provided to the LLMz
Show child attributes
Show child attributes
string
The unique identifier of the LLMz execution, prefixed with
llmz_any
The version of the LLMz engine or context
string
Optional instructions provided to guide the LLMz execution
LLMZ.Obj[]
A list of objects relevant to the LLMz context
LLMZ.Tool[]
A list of tools available for the LLMz engine to use
number
The current loop count of the LLMz iteration process
number
The temperature setting used for the LLM model
string
The name or identifier of the LLM model being used.
OAI.Message[]
The conversation transcript, including all prior messages in the current context
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:IncomingEvent
Information about the last incoming event in your bot’s execution.
Show child attributes
Show child attributes
string
required
The ID of the bot that experienced the event.
string
The ID of the conversation that the event took place in.
EventDirection
required
The direction of the event, indicating whether the event was received by the bot or sent from the bot.Possible values:
'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.
string
required
The unique identifier for the event.
string
The integration that the event occurred on.
object
Information about Knowledge Bases queried for the event.
Show child attributes
Show child attributes
Studio.KnowledgeBase.KB[]
required
Array of Knowledge Bases queried for the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
Studio.KnowledgeBase.ContentResult[]
Array of Knowledge Base results consulted for this event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
string
The unique identifier for the current event’s message.
object
required
The payload for the current event.
string
required
A representation of the event in plain text. If the event is text message, this property will contain the message itself.
EventState
required
Data related to the state of the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
EventTags
DM.Trigger
The Trigger that sent the event.
Show child attributes
Show child attributes
string
The ID of the conversation associated with this Trigger.
string
The name of the event that the Trigger sent.
string
required
The ID of the Workflow containing the Trigger.
string
The integration associated with the Trigger.
string
required
The ID of the Node that contains the Trigger.
string
The ID of the user associated with this Trigger.
string
required
The type of the event.
string
The user ID associated with this event.
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:IncomingEvent
Information about the last incoming event in your bot’s execution.
Show child attributes
Show child attributes
string
required
The ID of the bot that experienced the event.
string
The ID of the conversation that the event took place in.
EventDirection
required
The direction of the event, indicating whether the event was received by the bot or sent from the bot.Possible values:
'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.
string
required
The unique identifier for the event.
string
The integration that the event occurred on.
object
Information about Knowledge Bases queried for the event.
Show child attributes
Show child attributes
Studio.KnowledgeBase.KB[]
required
Array of Knowledge Bases queried for the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
Studio.KnowledgeBase.ContentResult[]
Array of Knowledge Base results consulted for this event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
string
The unique identifier for the current event’s message.
object
required
The payload for the current event.
string
required
A representation of the event in plain text. If the event is text message, this property will contain the message itself.
EventState
required
Data related to the state of the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
EventTags
DM.Trigger
The Trigger that sent the event.
Show child attributes
Show child attributes
string
The ID of the conversation associated with this Trigger.
string
The name of the event that the Trigger sent.
string
required
The ID of the Workflow containing the Trigger.
string
The integration associated with the Trigger.
string
required
The ID of the Node that contains the Trigger.
string
The ID of the user associated with this Trigger.
string
required
The type of the event.
string
The user ID associated with this event.
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:IncomingEvent
Information about the last incoming event in your bot’s execution.
Show child attributes
Show child attributes
string
required
The ID of the bot that experienced the event.
string
The ID of the conversation that the event took place in.
EventDirection
required
The direction of the event, indicating whether the event was received by the bot or sent from the bot.Possible values:
'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.
string
required
The unique identifier for the event.
string
The integration that the event occurred on.
object
Information about Knowledge Bases queried for the event.
Show child attributes
Show child attributes
Studio.KnowledgeBase.KB[]
required
Array of Knowledge Bases queried for the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
Studio.KnowledgeBase.ContentResult[]
Array of Knowledge Base results consulted for this event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
string
The unique identifier for the current event’s message.
object
required
The payload for the current event.
string
required
A representation of the event in plain text. If the event is text message, this property will contain the message itself.
EventState
required
Data related to the state of the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
EventTags
DM.Trigger
The Trigger that sent the event.
Show child attributes
Show child attributes
string
The ID of the conversation associated with this Trigger.
string
The name of the event that the Trigger sent.
string
required
The ID of the Workflow containing the Trigger.
string
The integration associated with the Trigger.
string
required
The ID of the Node that contains the Trigger.
string
The ID of the user associated with this Trigger.
string
required
The type of the event.
string
The user ID associated with this event.
After Turn End
This Hook type executes after a full turn has completed—meaning the bot has received user input, processed it, and responded. You can use a Hook of this type to track AI spend and token cost for your bot. Parameters:IncomingEvent
Information about the last incoming event in your bot’s execution.
Show child attributes
Show child attributes
string
required
The ID of the bot that experienced the event.
string
The ID of the conversation that the event took place in.
EventDirection
required
The direction of the event, indicating whether the event was received by the bot or sent from the bot.Possible values:
'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.
string
required
The unique identifier for the event.
string
The integration that the event occurred on.
object
Information about Knowledge Bases queried for the event.
Show child attributes
Show child attributes
Studio.KnowledgeBase.KB[]
required
Array of Knowledge Bases queried for the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
Studio.KnowledgeBase.ContentResult[]
Array of Knowledge Base results consulted for this event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
string
The unique identifier for the current event’s message.
object
required
The payload for the current event.
string
required
A representation of the event in plain text. If the event is text message, this property will contain the message itself.
EventState
required
Data related to the state of the event.
Since most of this object’s properties are for internal use by Botpress, we’ve omitted its deeper structure from this documentation.
EventTags
DM.Trigger
The Trigger that sent the event.
Show child attributes
Show child attributes
string
The ID of the conversation associated with this Trigger.
string
The name of the event that the Trigger sent.
string
required
The ID of the Workflow containing the Trigger.
string
The integration associated with the Trigger.
string
required
The ID of the Node that contains the Trigger.
string
The ID of the user associated with this Trigger.
string
required
The type of the event.
string
The user ID associated with this event.
IO.TurnMetadata
The turn’s metadata
Show child attributes
Show child attributes
IO.TokenReport
The token information and cost for the current turn
Show child attributes
Show child attributes
string
A summary of the token usage for the last turn
string
A detailed breakdown of token usage for the last turn
number
The number of billed tokens during the last turn
IO.TokenUsage[]
An array of token usages
Show child attributes
Show child attributes
number
The number of tokens in the usage
number
The AI spend for the usage (in nanodollars). To get the number in dollars, divide this number by 1,000,000,000.
number
The duration (in milliseconds) of the usage
string
The location in the Workflow where the usage occurred
boolean
Whether the usage was cached
number
The total number of tokens used in the last turn
number
The total number of billed tokens used in the last turn
number
The AI spend for the last turn (in nanodollars). To get the number in dollars, divide this number by 1,000,000,000.
number
The percentage of savings on AI spend for this turn.