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.
Input Transformer is configured by implementing the
handleInput function in the Transformer in the Endpoint.
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
The configuration object for the Endpoint. Contains the URLToken etc.
The Express request object with a JSON parsed body.
The Express response object.
The payload object contains the userId, sessionId, text and data that was sent through the Socket. It also contains the channel of the client.
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.
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 Transformerwill 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 2 months ago