Hooks
Customizable points that allow you to execute custom code in response to specific events.
Hooks in Botpress are powerful tools that enable you to customize the behaviour of your bot by executing custom code at specific points during its operation. Hooks allow you to intercept and modify messages, manage sessions, perform logging, integrate with external systems, and more. By leveraging hooks, you can fine-tune your bot's interactions and responses to meet your specific requirements.
Hooks can be customized similarly to the Execute Code cards and Validation fields.
Parameters
Hooks are functions that take parameters. The parameters are different depending on the hook type. event
is the most common parameter, and it is always available. The event object contains all the information about the event that triggered the hook.
Using Hooks
The instances where you can inject hooks into your bot's flow are as follows:
After Incoming Message
This hook is called right after all incoming middleware have processed the event but before the Dialogue Engine starts processing it. You can access all the required data (including NLU intent) for special processing and decide what happens to the event.
A typical operation here is to tell Botpress to ignore the event and not process it (e.g., not send it to the dialogue engine).
Before Incoming Message
Botpress calls this hook after receiving an event but before processing any middleware. It is possible to change event properties.
Botpress often uses this hook to set flags to skip some processing, for example, to prevent the QnA from processing it when it's a quick reply.
Before Outgoing Middleware
The Dialogue Manager calls this hook before the bot's reply is sent to the user.
Here you can save the bot's complete response.
Updated 3 months ago