> ## 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.

# Output 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 *Output Transformer* converts the Flow output. This transformer allows you to manipulate the Flow output before it's sent to the Endpoint.

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

The output transformer works differently for the following [Endpoint types](/ai/for-developers/transformers/overview#endpoint-types):

<Tabs>
  <Tab title="REST-based Endpoints">
    When using output transformers in REST Endpoints, you can't send multiple Flow outputs to the user. However, you can still have multiple Say Nodes in a Flow that are triggered by each user input.

    In this case, the `handleOutput` function stores the Say Node outputs in the `outputs` array. You can process the stored outputs with the [execution finished transformer](/ai/for-developers/transformers/execution-finished-transformer), which concatenates them into one output when the Flow execution has finished. This approach allows you to manipulate each Flow output in the `handleOutput` function and then concatenate them into one output with the execution finished transformer.

    ```mermaid theme={null}
    graph LR
    A[Flow output 1] --> B[Output Transformer]
    C[Flow output 2] --> B[Output Transformer]
    D[Flow output 3] --> B[Output Transformer]
    B --> E[outputs Array]
    E --> F[Execution Finished Transformer]
    F -- concatenated messages --> G[Endpoint]
    G --> H[User]
    ```
  </Tab>

  <Tab title="Webhook- and Socket-based Endpoints">
    When using output transformers in Webhook and Socket Endpoints, each Flow output is sent to the user. The return value of the `handleOutput` function is sent directly to the user and must comply with the [channel](/ai/agents/develop/nodes/channels) format.

    In this case, the `handleOutput` function takes an additional argument: `processedOutput`. This argument contains the output that would be sent as the correct format corresponding to the specific channel.

    ```mermaid theme={null}
    graph LR
    A[Flow output 1] --> B[Output Transformer]
    C[Flow output 2] --> B[Output Transformer]
    D[Flow output 3] --> B[Output Transformer]
    B -- message 1 --> E[Endpoint]
    B -- message 2 --> E[Endpoint]
    B -- message 3 --> E[Endpoint]
    E -- message 1 --> F[User]
    E -- message 2 --> F[User]
    E -- message 3 --> F[User]
    ```
  </Tab>
</Tabs>

## Transformer Function Arguments

Depending on the Endpoint type you are using, the function arguments vary:

<Tabs>
  <Tab title="REST-based Endpoints">
    | Argument  | Description                                                                  |
    | --------- | ---------------------------------------------------------------------------- |
    | endpoint  | The configuration object for the [Endpoint](#endpoint-configuration-object). |
    | output    | The raw output from the Flow.                                                |
    | userId    | The unique ID of the user.                                                   |
    | sessionId | The unique ID of the session.                                                |
  </Tab>

  <Tab title="Webhook- and Socket-based Endpoints">
    | Argument        | Description                                                                                                                                                           |
    | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | endpoint        | The configuration object for the [Endpoint](#endpoint-configuration-object).                                                                                          |
    | output          | The raw output from the Flow.                                                                                                                                         |
    | processedOutput | The processed output from the Flow to comply with the Endpoint format. This is the data that the Endpoint sends to the user if the output transformer isn't executed. |
    | userId          | The unique ID of the user.                                                                                                                                            |
    | sessionId       | The unique ID of the session.                                                                                                                                         |
  </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 output transformer return value depends on the Endpoint type in which you use the transformer. There is no validation of the output transformer return value. If the output transformer returns a falsy value, the output is discarded and not stored in the `outputs` array.

<Tabs>
  <Tab title="REST-based Endpoints">
    The `handleOutput` function returns a value and stores it in the `outputs` array. You can access this array with the `handleExecutionFinished` function. You can set the format of the `outputs` array items in the `handleOutput` function. By default, the `outputs` array entries have `text` and `data` properties. You can change the output format as follows:

    <Accordion title="Modify the Return Value Format">
      ```js theme={null}
      handleOutput: async ({ processedOutput, output, endpoint, userId, sessionId }) => {
      const modifiedOutput = {
          text: "text",
          data: {}
          // ...
      };

      return modifiedOutput;
      }
      ```
    </Accordion>
  </Tab>

  <Tab title="Webhook- and Socket-based Endpoints">
    The output transformer must return a value that can be sent directly to the specific channel. For example, if you're using the output transformer in a Sunshine Conversations Endpoint, the return value format must meet the [Sunshine Conversations message format](https://developer.zendesk.com/documentation/conversations/messaging-platform/programmable-conversations/sending-messages/).

    <Accordion title="Format Example for Sunshine Conversations Endpoints">
      ```js theme={null}
      handleOutput: async ({ processedOutput, output, endpoint, userId, sessionId }) => {
          const requestPayload = {
              author: {
                  type: "business"
              },
              content: {
                  type: "text",
                  text: "Hello world"
              }
          };
          
          return requestPayload;
      }
      ```
    </Accordion>
  </Tab>
</Tabs>
