> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognigy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Input Transformer

<Warning>
  In Cognigy.AI 2025.25.0, transformers will start using the `axios` library for handling HTTP requests internally instead of `request-promise`. This change occurs to improve security and maintainability. The following HTTP request options will still be supported:

  * **URL configuration** — `uri`, `url`
  * **Request method** — `method`
  * **Request headers and configuration** — `headers`
  * **Request body** — `form`, `json`
  * **Query parameters** — `qs`, `qsStringifyOptions`
  * **Authentication** — `auth`
  * **Connection and network** — `proxy`, `maxRedirects`, `gzip`, `encoding`

  If you use other HTTP request options, review your transformer code to ensure it is compatible with the `axios` library before the release of Cognigy.AI 2025.25.0.
</Warning>

The *Input Transformer* converts the user input after it's sent to an Endpoint. This allows you to manipulate the user input data before it is sent to the Flow, for example, to communicate with external systems, to implement integrations with a custom channel, and much more.

You can configure the input transformer in the `handleInput` function in the [Endpoint settings or via CLI](/ai/for-developers/transformers/overview#working-with-transformers).

## Restrictions

* The return value is validated against a set of rules. If these rules aren't met, the transformer throws an error. The following rules apply:

  * `userId` is a string with up to 256 characters.
  * `sessionId` is a string with up to 256 characters.
  * `text` is a string with up to 10,000 characters.
  * `data` is an object.

## Transformer Function Arguments

Depending on the Endpoint type in which you want to use the transformer, the function arguments vary:

<Tabs>
  <Tab title="Webhook- and REST-based Endpoints">
    | Argument | Description                                                                  |
    | -------- | ---------------------------------------------------------------------------- |
    | endpoint | The configuration object for the [Endpoint](#endpoint-configuration-object). |
    | request  | The Express request object with a JSON-parsed body.                          |
    | response | The Express response object.                                                 |
  </Tab>

  <Tab title="Socket-based Endpoints">
    | Argument | Description                                                                                                                                              |
    | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | endpoint | The configuration object for the [Endpoint](#endpoint-configuration-object).                                                                             |
    | payload  | The payload object contains the userId, sessionId, text, and data that was sent through the socket. The payload also contains the channel of the client. |
  </Tab>
</Tabs>

### Endpoint Configuration Object

<Accordion title="endpoint Object Properties">
  | Property              | Type      | Description                                                                                                             |
  | --------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------- |
  | `_id`                 | `string`  | The Endpoint's Reference ID.                                                                                            |
  | `channel`             | `string`  | The Endpoint's [channel](/ai/agents/develop/nodes/channels).                                                            |
  | `URLToken`            | `string`  | The URL Token, found in the [Input object](/ai/agents/deploy/endpoints/inject-and-notify#how-to-use-inject-and-notify). |
  | `name`                | `string`  | The Endpoint's name.                                                                                                    |
  | `flowId`              | `string`  | The Reference ID of the specified Flow to which the Endpoint points to.                                                 |
  | `entrypoint`          | `string`  | The Entrypoint of the Endpoint.                                                                                         |
  | `active`              | `boolean` | The flag to activate or deactivate the Endpoint.                                                                        |
  | `nluConnectorId`      | `string`  | ID of the selected NLU connector for the Endpoint.                                                                      |
  | `useAnalytics`        | `boolean` | The flag to collect analytics data for the Endpoint.                                                                    |
  | `storeDataPayload`    | `boolean` | The flag to store data payloads into analytics for the Endpoint.                                                        |
  | `useConversations`    | `boolean` | The flag to collect conversations history for the Endpoint.                                                             |
  | `maskIPAddress`       | `boolean` | The flag to mask sensitive IP addresses in input object and analytics data.                                             |
  | `maskAnalytics`       | `boolean` | The flag to mask sensitive data in analytics for the Endpoint.                                                          |
  | `maskLogging`         | `boolean` | The flag to mask sensitive data in logs for the Endpoint.                                                               |
  | `useContactProfiles`  | `boolean` | The flag to use Contact Profiles for the Endpoint.                                                                      |
  | `useDashbotAnalytics` | `boolean` | The flag to use Dashbot for collecting analytics data.                                                                  |
  | `dashbotApikey`       | `string`  | The API key of the Dashbot bot for analytics collection.                                                                |
  | `dashbotPlatform`     | `string`  | The selected platform of the Dashbot bot for analytics collection.                                                      |
  | `settings`            | `object`  | Optional Endpoint-specific settings. For example, Facebook Page token.                                                  |
  | `handoverSettings`    | `object`  | Settings to configure a handover provider.                                                                              |
  | `createdAt`           | `number`  | Unix timestamp when the Endpoint was created.                                                                           |
  | `lastChanged`         | `number`  | Unix timestamp when the Endpoint was last modified.                                                                     |
  | `createdBy`           | `string`  | Email of the user who created the Endpoint.                                                                             |
  | `lastChangedBy`       | `string`  | Email of the user who last modified the Endpoint.                                                                       |
</Accordion>

## Return Values

The input transformer returns the user ID, session ID, text, and data, which are subsequently sent to the Flow. These values are extracted from the Endpoint payload. The payload format is specific to the Endpoint type you use, for example, Alexa or Facebook (Meta) Messenger. Read the documentation of the [specific Endpoint](/ai/agents/deploy/endpoint-reference/overview) to know how to format the payload.

<Accordion title="Example of Transformer Return Values">
  ```js theme={null}
  return {
      userId: payload.userId,
      sessionId: payload.sessionId,
      text: payload.text,
      data: { "test": 1 }
  };
  ```
</Accordion>

### Undefined Return Values

If the transformer returns `undefined` for `userId`, `sessionId`, `text`, or `data`, this means that the transformer uses the value from the Endpoint.

<Accordion title="Example of Undefined Return Values">
  The following example overwrites `text` and `data`, but uses the `userId` and `sessionId` from the Endpoint:

  ```js theme={null}
  return {
      userId: undefined,
      sessionId: undefined,
      text: payload.text,
      data: { "test": 1 }
  };
  ```
</Accordion>

### Endpoints Event Messages

The Webchat and the Socket.IO Endpoints output event messages that indicate user activity, such as whether the user is connected (`user-connected`) or disconnected (`user-disconnected`). These event messages neither trigger Flows nor are counted. The event messages inform [handover providers](/ai/escalate/handovers) about user activity, allowing human agents to determine if the user is still engaged in the conversation. You can access the event messages with the `data._cognigy.event` property in the return value of the input transformer.

<Accordion title="Example of Return Values with Event Messages">
  ```js theme={null}
  return {
      "userId": payload.userId,
      "sessionId": payload.sessionId,
      "text": payload.text,
      "data": {
          "_cognigy": {
                "event": {
                  "type": "user-connected"
              }
          }
      }
  }
  ```
</Accordion>

If you want to access event messages in the input transformer, don't modify them. The event messages are only recognized if their data payload follows a specific format. The following code snippet shows how to use event messages in the input transformer:

<Accordion title="Example of Input Transformer with Event Messages">
  ```js theme={null}
  {
  handleInput: async ({ payload, endpoint }) => {
    if (!!payload.data?._cognigy?.event) {
  // pass on "event messages" without modification
        return payload;
      }

      // rest of your input transformer code
    }
  }
  ```
</Accordion>

### Transformers and Conversation Counts

Conversations in Cognigy.AI are counted if the input transformer returns any result but falsy.
