The Hooks Tab of the Explorer panel allows you to create Hooks. Hooks are custom code snippets that are executed synchronously when specific events occur in the conversation such as a user or the bot sending a message. They can be customized similarly to Execute Code cards and Validation fields.

πŸ“˜

Note

Editing a hook takes immediate effect, which means it will execute with the changes on the next event. This makes development a lot faster.

Hooks are differentiated using the point in the event engine when they are executed. The following are instances where you can inject hooks into your code.


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.


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.