Notification API WebSocket reconnection loop in Node.js causing rate limits

I’m building a Node.js listener for the CXone Notification API. The standard ws library works fine for the initial connection, but the reconnection logic is messy. When the server sends a close frame (code 1001), my script immediately tries to reconnect. This triggers a 429 Too Many Requests error from the gateway because the backoff isn’t aggressive enough.

Here’s the relevant :

ws.on('close', (code, reason) => {
 console.log(`Connection closed: ${code}`);
 if (code !== 1000) {
 // Immediate retry fails
 connect(); 
 }
});

I need a reliable way to handle the exponential backoff without losing messages during the gap. The @genesys/cloud-pure-client-javascript SDK doesn’t seem to expose the raw WebSocket event stream directly, so I’m stuck using the raw /api/v2/platform/notification/websocket endpoint. Is there a recommended pattern for managing the reconnect delay in or via a simple script? I can’t find a clear example in the docs for handling the close codes properly.

You’re hammering the gateway because you’re ignoring the exponential backoff. Add a jitter delay before reconnecting to stop the 429s.

const delay = (ms) => new Promise(res => setTimeout(res, ms));
ws.on('close', async () => await delay(Math.random() * 1000 + 1000) && connect());

It’s basic rate limit handling. The docs mention this in the WebSocket section.