Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
excludeRelated Articles

The prehook is a middleware introduced to customize the payload before sending in the request to the intent nodes.

All the intent type requests except for launch, session end, listener event nodes can trigger the prehook nodes based on the configuration.

Pre Hook Request node

Before triggering the intent, the Pre Hook Request node will be triggered.

Name - Custom name given to the node.

Skill - The project name.

Intent - You can choose the intents for which this Pre hook request node should be triggered. The Prehook request node will be triggered for the intents listed in this field irrespective of the state.

Note

There should only be one prehook request node per project.

Prehook handler

The basic code given below will handle the requests from the Prehook node.

Place the below code in the function node after the Pre Hook Request node.

Code Block
msg.payload.handleRequest = false;
msg.payload.preHookData = {name: 'arun'};
return msg;

The msg.payload.handleRequest takes boolean values. This property decides if the content from the Prehook Request node should pass through to the corresponding intent.

  • If set to true, the corresponding intent will not get triggered. The Pre Hook Response node will act as a normal Response node.

  • If set to false, the Pre Hook Response node will trigger the corresponding intent will get triggered. The (s), that triggered the Prehook Request node, appending the data stored in msg.payload.preHookData will get appended.

While using the Flow studio, when the flow passes through the custom response in prehook, you can use msg.orbita.session.property to pass the orbita session values to the next control.

Pre Hook Response node

The Based on the msg.payload.handleRequest property, the Pre Hook Response node will either send the output payload based on the msg.payload.handleRequest property.payload to the server or trigger the corresponding intent that triggered the Pre Hook Request node.

Name - Custom name given to the node.

Prehook usage

For example,

  • you can force an anonymous user to login to log into the chatbot for answering certain sensitive questions or

  • you can count the number of times the fallback intent is triggered or

  • you can redirect a user to use another flow when a specific intent is triggered.

In the below example, using any intent will invoke the login directive if the user is not logged in.

Image RemovedImage Added

When the chatbot user triggers any intent, the prehook node is invoked and checks if the user is logged in or not. If the user is already logged in, the chatbot replies with the corresponding response for the intent. If the user is not logged in, the login directive will be invoked.

If an anonymous user, any intent he/she tries will invoke the login directive.

Code Block
msg.payload.handleRequest = true;

Image Modified

For a logged-in user, the chatbot will answer for the triggered intent.

Code Block
msg.payload.handleRequest = false;

Image Modified

The example flow is attached below.

View file
namePrehook.json

Related Articles

Filter by label (Content by label)
showLabelsfalse
max5
showSpacefalse
cqllabel = "experience-manager"