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

# Socket.IO

<Frame>
  <img class="image-center" src="https://mintcdn.com/cognigy-15abf2ba/nRSdAucuLUeDXgwa/_assets/ai/deploy/endpoint-reference/socket-io.svg?fit=max&auto=format&n=nRSdAucuLUeDXgwa&q=85&s=6b16af2ce2ef7d55dd7fd9937ff434ff" alt="Socket.IO Endpoint logo" width="143" height="43" data-path="_assets/ai/deploy/endpoint-reference/socket-io.svg" />
</Frame>

<Warning>
  As of Cognigy.AI 4.97.0, the Handover Providers section in the Endpoint settings is deprecated. From Cognigy.AI 2026.4 on, the Handover Settings section in the Endpoint settings is in read-only mode. You can't use this section to configure new handover providers. You can still view configured handover provider settings, but you can't change them.
  To configure handover providers, use the [Handover Providers](/ai/escalate/migration) interface, which offers greater flexibility for managing your integration with contact centers.
  For a smooth migration, refer to the [migration guide](/ai/escalate/migration).
</Warning>

The Socket.IO Endpoint enables you to connect your AI Agent to the Socket.IO client.

## Prerequisites

* Familiarity with the [Socket.IO library](https://socket.io/).
* Setup of the [Cognigy Socket.IO client](https://github.com/Cognigy/SocketClient).

## Generic Endpoint Settings

Learn about the generic Endpoint settings on the following pages:

* [Endpoints Overview](/ai/agents/deploy/endpoints/overview)
* [NLU Connectors](/ai/platform-features/nlu/external/nlu-connectors/overview)
* [Data Protection & Analytics](/ai/agents/deploy/endpoints/data-protection-and-analytics)
* [Transformer Functions](/ai/for-developers/transformers/overview)
* [Real-Time Translation Settings](/ai/agents/deploy/endpoints/real-time-translation-settings)
* [Handover Settings](/ai/agents/deploy/endpoints/handover-settings)
* [Inject and Notify](/ai/agents/deploy/endpoints/inject-and-notify)
* [Copilot](/agent-copilot/configure/copilot-section)

## How to Set Up

### Setup on the Cognigy.AI Side

<Accordion title="1. Configure a Socket.IO Endpoint">
  1. In the left-side menu of your Project, click **Deploy > Endpoints**.
  2. On the **Endpoints** page, click **+ New Endpoint**.
  3. In the **New Endpoint** section, do the following:
     1. Select the **Socket.IO** Endpoint type.
     2. Specify a unique name.
     3. Select a Flow from the list. Save changes.
  4. In the Endpoint editor, go to the **Configuration Information** section and copy the URL from the **Endpoint URL** field.
     The Endpoint URL consists of two parts separated by a slash:

     * The server address (`<Socket-Endpoint-URL>`), for example, `https://endpoint-trial.cognigy.ai`.
     * The token (`<URLToken>`) that comes after the slash, for example, `0e77b9a19f33cb68b3f528b3b28d4b32386162559160ceb9ec85036d83dd8f8b`.

     For further configuration, you need to use these two parts separately.
</Accordion>

### Setup on the Third-Party Provider Side

<AccordionGroup>
  <Accordion title="1. Send a Request">
    <Tabs>
      <Tab title="Cognigy Socket.IO client">
        ```js theme={null}
        const { SocketClient } = require("@cognigy/socket-client");

        (async () => {
          // Create the SocketClient with the server address + URL Token + optional options
          const client = new SocketClient(
            "https://endpoint-trial.cognigy.ai",             // the Socket.IO Endpoint server address
            "0e77b9a19f33cb68b3f528b3b28d4b32386162559160ceb9ec85036d83dd8xxx", // the Socket.IO URL token
            {
              userId: "user@cognigy.com",  
              sessionId: "session123", 
              forceWebsockets: true 
            }
          );

          // Listen for messages from the AI Agent
          client.on("output", (output) => {
            console.log("AI Agent:", output.text);
            console.log("Additional data:", output.data);
          });

          // Listen for errors
          client.on("error", (error) => {
            console.error("AI Agent error:", error.message);
          });

          // Listen for finalPing (bot done processing)
          client.on("finalPing", () => {
            console.log("AI Agent finished processing a message");
          });

          // Connect to the Socket.IO Endpoint
          await client.connect();

          // Send a message — BASIC
          client.sendMessage("Hello from test!");

          // Send a message — WITH EXTRA DATA
          client.sendMessage(
            "Example text with custom data",
            {
              passthroughIP: "127.0.0.1", // custom IP if needed
              resetFlow: false,           // false means: continue Flow
              key: "value"                // any custom data for your Flow
            }
          );

          // Reset the Flow if needed
          // client.sendMessage(
          //   "Starting fresh!",
          //   {
          //     resetFlow: true
          //   }
          // );
        })();
        ```
      </Tab>

      <Tab title="Other clients">
        Messages are sent using the processInput event with a payload in the following format:

        ```json theme={null}
        {
            "URLToken": "urlToken",
            "sessionId": "sessionId",
            "userId": "user@cognigy.com",
            "passthroughIP": "127.0.0.1",
            "resetFlow": "false",  // Resets the Flow and starts a new one from the beginning
            "text": "Example text",  // Can be skipped with "resetFlow": true
            "data": {
                "key": "value"
            }
        }
        ```

        | Parameter     | Type    | Description                                                                                                                                                                                                                                                                     | Required                      |
        | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
        | URLToken      | String  | An authentication token for connecting to the Endpoint.                                                                                                                                                                                                                         | Yes                           |
        | userId        | String  | The ID of the end user.                                                                                                                                                                                                                                                         | Yes                           |
        | sessionId     | String  | The ID used to track the current session and maintain its state. Generate a new unique ID for each new session. For testing, you can use any string and change it whenever you want to start a new session.                                                                     | Yes                           |
        | passthroughIP | String  | The IP address of the user, used for logging or tracking purposes.                                                                                                                                                                                                              | No                            |
        | resetFlow     | Boolean | When set to `true`, resets the conversation Flow. This payload may or may not contain a message. If it contains a message, it will be the first in the new Flow. Make sure to set `resetFlow` to `false` for subsequent messages to continue the Flow instead of restarting it. | Yes                           |
        | text          | String  | The text that the assigned Flow should process.                                                                                                                                                                                                                                 | No, if `resetFlow` is `true`. |
        | data          | Object  | The data that the assigned Flow should process.                                                                                                                                                                                                                                 | No                            |
      </Tab>
    </Tabs>
  </Accordion>

  <Accordion title="2. Get a Response">
    Messages can be received by listening to the `output` event. The responses have the following format:

    <Tabs>
      <Tab title="Cognigy Socket.IO client">
        ```text theme={null}
        AI Agent: I’d be happy to help. Could you please provide your order number?
        Additional data: {}
        AI Agent finished processing a message
        ```
      </Tab>

      <Tab title="Other clients">
        ```json theme={null}
        {
          "type":"output",
          "data":
          {
            "text":"responseText",
            "data":
            {
              "key":"value"
            }
          }
        }
        ```
      </Tab>
    </Tabs>
  </Accordion>
</AccordionGroup>
