Audio latency spikes and the socket resets immediately after this log.
[2023-10-27 14:02:11] WebSocket connection closed abnormally (code: 1006)
Tried these:
- Increased AppFoundry timeout to 60s
- Disabled Nagle’s algorithm on the proxy
- Checked firewall rules for port 443
Snippet for the connect logic:
const ws = new WebSocket('wss://api.mypurecloud.com/api/v2/analytics/events');
ws.onopen = () => console.log('Connected');
ws.onerror = (err) => console.error('WS Error', err);
Cognigy side throws a timeout on the first audio chunk.
The docs state: “WebSocket connections must include an Authorization header with a valid Bearer token.” You’re likely hitting the idle timeout because the token isn’t being refreshed or validated correctly during the handshake. Code 1006 usually means the server closed the connection without proper closure sequence, often due to auth failure or payload size issues.
Check if you’re sending the token in the header or subprotocol. The standard Genesys Cloud WebSocket endpoint expects:
const ws = new WebSocket('wss://api.mypurecloud.com/api/v2/analytics/events/realtime', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
If you’re using a proxy, ensure it’s not stripping the header. Also, verify the token scope includes analytics:realtime:read. Missing scopes cause immediate disconnects. Try logging the handshake response headers. If you see a 401 or 403, that’s your culprit. Don’t forget to handle the onclose event to retry with a fresh token if needed.