- Go to Build > NLU Connectors and create a Code connector.
- Add your JavaScript code to the Transformer section and activate the Enable Code Transformer toggle.
Code Example with Description
Code Example with Description
| Description | |
|---|---|
| Function and its parameters | |
createNluCodeTransformer | This function create a transformaer that asynchronously sends the message (text) to an external NLU service for analysis. The function processes the response from the service, populates the nluResult object with values such as intent, type, slots, and intentScore, and returns the data object unchanged, unless explicitly modified. |
text | The message received from the endpoint, such as user input, that needs to be analyzed by the NLU service. |
data | The data object associated with the message, containing additional metadata or context about the request. This object can be modified or passed through unchanged. |
language | The language code of the locale, representing the language in which the message is processed. For example, en for English, de for German. |
| NLU Result Initialization | Initial values set for the NLU result object to ensure structure before any processing occurs. |
intent | Initially null, it will be populated with the Intent detected from the message, for example, book_flight or greet_user, after processing. |
type | Initially null, it refers to the type of Intent, for example, action, informational. Will be set based on the NLU service’s response. |
slots | Initially {}, this object holds the extracted parameters (Slots) that are associated with the detected intent, for example, destination, date, and class. |
intentScore | Initially 0, it represents the confidence score (ranging from 0 to 1) indicating how confident the NLU service is in the detected Intent. |
nlu | An object containing metadata about the Intent: - intentId - initially null, the unique identifier for the detected Intent. - intentFlow - initially null, the Flow associated with the Intent. |
| Return Object | The function returns the data and nluResult. |
data | The unchanged data object passed in, which may contain context or additional information. |
nluResult | The object returned after processing, containing the final intent, slots, intentScore, and any other details extracted from the message using the NLU logic. |