We’re building a Node.js service to subscribe to Genesys Cloud routing:conversation events via the Notification API WebSocket. The goal is to maintain a stable connection and inject OpenTelemetry trace context into our downstream processing pipeline.
The connection works fine initially, but when the server restarts or there’s a network blip, the reconnection logic seems to miss events that occurred during the downtime. We’re using the standard w3c-websocket library. Here’s the reconnection snippet:
let ws = new WebSocket('wss://api.mypurecloud.com/api/v2/analytics/events');
ws.on('close', (code, reason) => {
console.log(`WebSocket closed: ${code}`);
setTimeout(() => {
ws = new WebSocket('wss://api.mypurecloud.com/api/v2/analytics/events');
// Re-subscribe logic here
}, 5000);
});
The issue is that after reconnecting, we don’t see any catch-up events. The Genesys docs mention that the server might send a control message with a lastSequenceId or similar to help with resuming, but we’re not seeing that in our logs. We just get a fresh stream.
Is there a specific header or subscription parameter we need to pass during reconnection to fetch missed events? Or do we need to poll the REST API for a range of events to bridge the gap? The current gap breaks our trace continuity.
[2023-10-27T08:15:22.123Z] WebSocket connected
[2023-10-27T08:15:23.456Z] Received subscription confirmation
[2023-10-27T08:20:11.789Z] WebSocket closed: 1006
[2023-10-27T08:20:16.790Z] Reconnecting...
[2023-10-27T08:20:17.012Z] WebSocket connected
// No events received until new conversation starts
Any pointers on handling this gap?