Input Transformer
Description

The Input Transformer
is triggered on every message from the user before the Flow is executed. This makes it possible to manipulate the text before it has been sent to the Flow, communicate with external systems, implement integrations with a new channel, and much more.
The Input Transformer
is configured by implementing the handleInput
function in the Transformer in the Endpoint.

Transformer Function Arguments

The handleInput
function gets a configuration object as an argument. This object always contains the key endpoint
, which contains the Endpoint configuration. The rest of the keys in the object depends on the base type of the Transformer. An overview of the keys in the object can be seen below
Argument | Description | Webhook Transformers | REST Transformers | Socket Transformers |
---|---|---|---|---|
endpoint | The configuration object for the Endpoint. Contains the URLToken etc. | X | X | X |
request | The Express request object with a JSON parsed body. | X | X | |
response | The Express response object. | X | X | |
payload | The payload object contains the userId, sessionId, text and data that was sent through the Socket. It also contains the channel of the client. | X |
Return Values of the Transformer

The Input Transformer
has to return a valid user ID, session ID and text and/or data that should be sent to the Flow. These values should be extracted from the body of the request. It is important to note that the format of the request body will differ based on the specific channel being used, i.e. a request from Alexa looks very different compared to a request from Facebook Messenger. It is, therefore, necessary to read the documentation from the specific channel to know how the request body is formatted.
If the Input Transformer
returns a falsy value, then the message from the user is never sent to the Flow.
Return Value Validation
The return value of the
Input Transformer
will be validated against a set of rules and rejected if the rules are not met. The rules are:
- The user ID is required in the return value. It has a max length of 256 characters.
- The session ID is required. It also has a max length of 256 characters.
- The text is not required. but has a max length of 10000 characters.
- The data object is not required.
If neither text or data is defined, then validation also fails.
Updated about 3 years ago