I’m trying to instrument our Genesys Cloud environment with New Relic by capturing real-time conversation state changes. The plan is to maintain a persistent WebSocket connection to the Notification API and pipe the events into New Relic custom events via a Node.js proxy.
The connection handshake works fine initially, but the socket closes with code 1000 (Normal Closure) the moment I send the subscription payload for routing.queue or conversation events. No error event is fired, just a clean disconnect.
Here’s the connection logic using the standard WebSocket library:
const WebSocket = require('ws');
const ws = new WebSocket('wss://api.us.genesyscloud.com/api/v2/notifications');
ws.on('open', () => {
const subscription = {
"subscribedEventTypes": [
"routing.queue.event"
],
"includeEventTypes": [
"routing.queue.update"
],
"filters": {
"routing.queueId": "1234567890"
}
};
console.log('Sending subscription...');
ws.send(JSON.stringify(subscription));
});
ws.on('close', (code, reason) => {
console.log(`Connection closed: ${code} - ${reason}`);
});
The auth header is passed during initialization using a valid OAuth bearer token. I’ve verified the token has notifications:subscribe scope. The server accepts the connection, I see the ‘Sending subscription…’ log, and then immediately the close event fires with code 1000 and an empty reason string.
I tried narrowing the filter to a specific queue ID that definitely exists and has active agents. Same result. If I omit the filters object entirely, the connection stays open but floods me with events I don’t need, which isn’t viable for production monitoring.
Is there a specific syntax requirement for the subscription payload when using the raw WebSocket API versus the SDK? The documentation examples seem sparse on error handling for subscription rejections. I need to know why the server is silently dropping the connection upon receiving the subscription request.