> For the complete documentation index, see [llms.txt](https://docs.aisera.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aisera.com/apis/apis/conversation-api-and-websocket/websocket.md).

# Websocket

## Setup

Complete the steps mentioned in the [Setup guide](/apis/apis/conversation-api-and-websocket/setup-and-authorization.md).

## Use

Use the following code to review conversation message types that you can use with the Aisera Conversation Websocket.

Most other usage details are same as those for the [Conversation API](/apis/apis/conversation-api-and-websocket/api-overview.md).

### Sample Requests

You can use the following sample payloads to create requests using websockets with the Conversation Websocket.

1. **Basic Request**

```
{
    "token": "<token>",
    "userId": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "text": "Contact live agent",
        "sessionVars": {},
        "reqId": "1",
        "isKL": false
    }
}
```

2. **Interactive Requests**

```
{
    "token": "<token>",
    "userId": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "sessionVars": {},
        "isKL": false,
        "userFullName": "Mark Smith",
        "text": "This is what I was looking for",
        "reqId": "REQ123",
        "followUpId": "R:0e70f8b8-6f6c-4ee5-8d26-6a8375e9bcea"
    }
}
```

3. **Form Submit Requests**

```
{
    "token": "<token>",
    "userid": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "sessionVars": {},
        "isKL": false,
        "userFullName": "Mark Smith",
        "text": "",
        "reqId": "REQ123",
        "channelCapabilities": {
            "isFormSupported": true
        },
        "followUpData": {
            "formId": "bcbed7df-951f-4369-b5f0-443ef31e2372",
            "formFieldValues": {
                "simpleStringSample": "Quick brown fox",
                "textAreaSample": "The quick brown fox jumps over the lazy dog.",
                "dateSample": "2021-11-17",
                "dropdownSample": "option3",
                "radiosSample": "option2",
                "multiSelectCheckboxesSample": ["check1", "check2"],
                "numberSample": 6,
                "booleanSample": true
            }
        }
    }
}

```

4. **SessionVar Requests**

```
{
    "token": "<token>",
    "userid": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "isKL": false,
        "channelId": "f9975e56-84dd-cbfb-e171-1785ae4b1282",
        "userFullName": "Mark Smith",
        "text": "test sessionVars",
        "reqId": "REQ123",
        "sessionVars": {
            "myVar": "someValue"
        },
        "channelCapabilities": {
            "isFormSupported": true,
            "isPopupSupported": false
        }
    }
}
```

5. **Needs Session History Requests**

```
{
    "token": "<token>",
    "userid": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "sessionVars": {},
        "isKL": false,
        "userFullName": "Mark Smith",
        "needsSessionHistory": true,
        "reqId": "REQ123",
        "channelCapabilities": {
            "isFormSupported": true,
            "isPopupSupported": false
        }
    }
}
```

6. **IsReset Requests**

```
{
    "token": "<token>",
    "userid": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "sessionVars": {},
        "isKL": false,
        "userFullName": "Mark Smith",
        "isReset": true,
        "reqId": "REQ123",
        "channelCapabilities": {
            "isFormSupported": true,
            "isPopupSupported": false
        }
    }
}
```

7. **Logout User - Finish Current Session**

```
{
    "token": "<token>",
    "userid": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "sessionVars": {},
        "isKL": false,
        "userFullName": "Mark Smith",
        "text": "/logout",
        "reqId": "REQ123",
        "channelCapabilities": {
            "isFormSupported": true,
            "isPopupSupported": false
        }
    }
}

```

8. **Go Back**

```
{
    "token": "<token>",
    "userid": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "sessionVars": {},
        "channelId": "f9975e56-84dd-cbfb-e171-1785ae4b1282",
        "userFullName": "Mark Smith",
        "followUpId": "_go:back_",
        "followUpContext": {
            "type": "FlowGoBack"
        },
        "reqId": "REQ123",
        "channelCapabilities": {
            "isFormSupported": true,
            "isPopupSupported": false
        }
    }
}
```

9. **Start Over**

```
{
    "token": "<token>",
    "userid": "<userid>",
    "userEmail": "<userEmail>",
    "channelId": "<channelId>",
    "data": {
        "sessionVars": {},
        "userFullName": "Mark Smith",
        "followUpId": "_go:back_",
        "followUpContext": {
            "type": "FlowStartOver"
        },
        "reqId": "REQ123",
        "channelCapabilities": {
            "isFormSupported": true,
            "isPopupSupported": false
        }
    }
}
```

## Websocket Client Files

Your Aisera team can provide you with a .zip package for a websocket client. If you don't receive the .zip package, you can build one using the following files.

### Message Types

```
// modeType in conversation server response
LiveAgentResponse: "LiveAgent",
LiveAgentWaiting: "LiveAgentWaiting",
LiveAgentJoined: "LiveAgentJoined",
LiveAgentExited: "LiveAgentExited",
LiveAgentWaitingUpdate: "LiveAgentWaitingUpdate",
LiveAgentTyping: "LiveAgentTyping",

Error: "Error",
FormError: "FormError",
ExternalSystemError: "ExternalSystemError",
FlowStarted: "FlowStarted",
FlowCompleted: "FlowCompleted",

SilentModeAnswerFound: "SilentModeAnswerFound",
SilentModeAnswered: "SilentModeAnswered",
SilentModeAnsweredConfidentially: "SilentModeAnsweredConfidentially",
SilentModeFirstResponse: "SilentModeFirstResponse",
SilentModeResolved: "SilentModeResolved",
SilentModeEscalated: "SilentModeEscalated",
SilentModeTicketCreated: "SilentModeTicketCreated",
SilentModeCancelled: "SilentModeCancelled",
SilentModeFollowUp: "SilentModeFollowUp",
SilentModeConversationEnded: "SilentModeConversationEnded",

SilentModeStopResponding: "SilentModeStopResponding", // Not sent from/to conversation server; handled by chatbot

// type in conversation server requests
LiveAgentPickUp: "LiveAgentPickUp",
LiveAgentCompleted: "LiveAgentCompleted",
LiveAgentTransfer: "LiveAgentTransfer",

SessionTimeout: "SessionTimeout",
EndSessionSurvey: "EndSessionSurvey",

// streaming responses
StatusUpdate: "StatusUpdate",
StreamingInProgress: "StreamingInProgress", // RAG answer in progress
StreamingCompleted: "StreamingCompleted",  // RAG answer completed

// campaign
Campaign: "Campaign",
AskForApproval: "AskForApproval"
```

### Postman Collection

{% hint style="info" %}
Postman Collections for websockets cannot currently be exported. Please refer the screenshots below to setup and test your websocket using Postman.
{% endhint %}

<figure><img src="/files/yow9F6ayEm0b5fN2omKc" alt=""><figcaption><p>Websocket request and response</p></figcaption></figure>

<figure><img src="/files/iJDpxADpOwqI3S5iQg9R" alt=""><figcaption><p>Websocket variables / configurations</p></figcaption></figure>

<div align="left"><figure><img src="/files/Fisdamur0ulrhK36kmCL" alt="" width="289"><figcaption><p>Setting up event listeners</p></figcaption></figure></div>

<figure><img src="/files/ztz7HiBWkuaEBStQj1fh" alt=""><figcaption><p>Websocket settings</p></figcaption></figure>

### Sample Client Implementation

The ReadMe file in the package will help you configure and run the sample client.

{% file src="/files/ha0PmQXPG6BQA9BXo92b" %}
