I’m building a custom chat interface to replace the standard widget for a client who wants a fully branded experience. We are using the raw WebSocket Guest API instead of the embeddable widget SDK to have full control over the UI components. The initial handshake works fine. I get the sessionId back from the HTTP POST to /api/v2/conversations/messaging/guests and then establish the WebSocket connection to wss://api-us-east-1.genesyscloud.com/api/v2/conversations/messaging/guests/{sessionId}/ws.
The connection stays alive for about 5 minutes if there is no activity. Then it just closes. I don’t get a specific error code in the close event, just a generic 1006 abnormal closure. I’ve tried sending a ping frame every 20 seconds using the WebSocket ping method, but that doesn’t seem to keep the connection alive. The server doesn’t respond to the ping with a pong either.
Here is how I’m setting up the WebSocket client in JavaScript:
const ws = new WebSocket(wsUrl);
ws.onopen = () => {
console.log('Connected');
setInterval(() => {
ws.ping(); // This doesn't seem to work
}, 20000);
};
ws.onclose = (event) => {
console.log('Closed:', event.code, event.reason);
// Reconnect logic here
};
I’ve read the documentation on the Guest API, but it doesn’t mention a specific keep-alive mechanism for the WebSocket connection. Is there a specific message type I need to send to keep the session active? Or is there a timeout setting I can configure on the messaging application side to extend the idle timeout? I don’t want to have to reconnect every 5 minutes if the agent is just thinking about a response. It creates a bad user experience with the UI flickering as the connection drops and reconnects.