Can anyone clarify why my Node.js consumer silently drops Analytics Notification events immediately after a WebSocket reconnect?
I am building a security audit pipeline that streams Genesys Cloud Notification API events to a Kafka topic. The goal is to capture every user.login and user.logout event for real-time alerting. I am using the ws library in a Node.js 18 environment. The initial connection works fine. I subscribe to the analytics:notification channel. I receive the first batch of events. However, when I simulate a network drop and reconnect, the subscription seems to persist, but the event payload structure changes slightly, causing my parser to fail. I am getting undefined for the eventType field on the second batch. I have verified the OAuth token is valid. I am using a fresh access token from the /oauth/token endpoint. The token has the view:notification scope. I am not seeing any 401 Unauthorized errors. The issue appears to be in the event deserialization logic. I suspect the WebSocket reconnection handshake might be sending a stale subscription ID. I am resetting the subscription on every open event. I am not using the official SDK for the WebSocket part because I need raw control over the reconnection logic for my audit requirements. I am using the REST API for token management. I am confident the Kafka producer is working. The issue is strictly in the consumption and parsing of the Genesys Cloud event stream. I need to ensure no events are lost during the reconnection window. This is critical for our compliance audits. I have checked the Audit API logs and confirmed the events were generated by Genesys Cloud. They just never made it to Kafka. Here is my reconnection logic and event handler:
const ws = new WebSocket(wssUrl, { headers: { Authorization: `Bearer ${token}` } });
ws.on('open', () => {
console.log('Connected to Genesys Cloud WSS');
const subscription = {
channel: 'analytics:notification',
filter: { eventType: ['user.login', 'user.logout'] }
};
ws.send(JSON.stringify(subscription));
});
ws.on('message', (data) => {
const event = JSON.parse(data);
console.log('Received event:', event.eventType);
// Producer.send(event);
});
The first message logs correctly. After a reconnect, the log shows undefined. Why does the eventType field disappear or become inaccessible after the first reconnection? Am I missing a step in the WebSocket subscription refresh process? Do I need to explicitly unsubscribe before resubscribing? Or is this a known behavior with the Notification API stream?