Websockets connections for Live agent Routing
The WebSocket protocol is an event driven API that enables two-way communication over a single, persistent, low latency TCP connection without the overhead of HTTP request/response. This can be referred to as a full duplex connection.
HTTP agents now have the ability to maintain WebSocket connections. This means that as long as WebSocket communication is set up, any client can directly interact with your HTTP Virtual Agent.
This allows you to enjoy the benefits of asynchronous flows, such as using the live agent node to route the conversation from a virtual agent to a human agent
WebSocket Protocol is currently the only means of connecting your HTTP virtual agent to a live agent.
HTTP agents can support both synchronous (HTTP request/response) and asynchronous (WebSockets) communication and should work without any additional changes. However the means of communication is dependent on the way the client is set up to communicate with the virtual agent.
Communication with virtual agents using WebSockets is similar to HTTP requests.
Before you connect your client app using WebSockets to your Virtual agent, you will need to send an init HTTP request, which is the same init endpoint as the HTTP request/response use case.
For EU based agents:
For US based agent:
You need to use your X-Vgai-Key to authenticate.
The body of the request looks as follows:-
The response received will be as follows:-
The “session_token” is valid only for interacting with a single session. If the token is attempted to be used for other sessions you will receive an invalid response.
We recommend running the init request on your server side, so that your X-Vgai-Key is not exposed to your client.
Once you get the session_token, you can connect using any WebSockets client you choose to the studio and interact with your Virtual Agent.
You can then use the following region specific WebSockets URLs:-
The message syntax should be as follows:
“input “: “your input”
When does the WebSocket communication disconnect?
- 1.When the client closes the connection
- 2.When session has ended in either of the following cases:-
- 1.Due to the flow ending.
- 2.Due to the session running for more than 24 hours.
- 3.After 10 minutes of idle time.