- Modify the incoming message from the Endpoint before it’s sent to the NLU engine.
- Adjust the response from the NLU engine before it reaches the Flow execution.
Restrictions
- NLU transformers operate only on data exchanged with the NLU engine. They don’t modify the prompt or response of an LLM Prompt Node or AI Agent Node.
NLU Code transformer
With the NLU Code transformer, you can write a custom NLU pipeline in the Code Editor.Transformer Settings
You can control the NLU Code transformer’s behavior by enabling or disabling functions in the Transformer Settings.Example of the `transformerStack` object in the Interaction Panel
Example of the `transformerStack` object in the Interaction Panel
Available Modules
httpRequest
httpRequest
You can send HTTP requests to external services, for example, third-party NLU engines, from within a transformer.
All transformer functions can access the
httpRequest module for this purpose.
The module is invoked as a function which takes a single configuration object as arguments.
This object has the same format as the options object for the NPM module Request.Example:getCognigyNlu
getCognigyNlu
You can execute Cognigy NLU from within a transformer. All NLU transformer functions can access the
getCognigyNlu function. This function takes string as arguments.Example:getSessionStorage
getSessionStorage
SessionStorage is a storage object available to all transformer functions and stays active throughout the session.
This object can store variables for later use in other functions or track the conversation state.
You can access it using the getSessionStorage function.
This function returns a Promise that resolves to the sessionStorage object, which you can use as a JavaScript regular object.Modifying variables inside StorageSession can lead to several problems:- Inconsistent State You might change the object in a way that other parts of your application don’t expect, which can cause errors or unexpected results.
- Asynchronous Issues. Since JavaScript is asynchronous, other operations might try to access the session storage before your changes are applied, causing issues such as reading outdated data.
SessionStorage.Example:NPM Modules
NPM Modules
The following NPM modules are available in the transformer:
Logging
Logging
You can use the exposed modules
console.log, console.info, and console.error in the transformers to display logs on the Logs page.