We’ve been trying to pipe real-time streaming analytics events into our internal Kafka topic for some custom reporting. The plan was to use the Notification API to subscribe to the analytics.events topic and then fan those out via a Node.js consumer script.
I’m using the standard genesys-cloud-node-sdk for auth and the WebSocket client for the actual stream. The subscription works fine in Postman, but as soon as I spin up the Node script, I get a steady stream of events for about 10 minutes, then the connection just hangs. No error, no disconnect event. Just silence.
Here’s the basic setup:
const { PlatformClient } = require('@genesyscloud/genesyscloud-node-sdk');
const WebSocket = require('ws');
const client = PlatformClient.init({
clientId: process.env.GENESYS_CLIENT_ID,
clientSecret: process.env.GENESYS_CLIENT_SECRET,
environment: process.env.GENESYS_ENVIRONMENT || 'mypurecloud.com'
});
async function startStream() {
const token = await client.auth.getOAuthToken();
const wsUrl = `wss://${process.env.GENESYS_ENVIRONMENT || 'mypurecloud.com}/api/v2/analytics/events`;
const ws = new WebSocket(wsUrl, {
headers: {
'Authorization': `Bearer ${token.access_token}`,
'Content-Type': 'application/json'
}
});
ws.on('open', () => {
const subscription = {
topic: 'analytics.events',
filter: {
query: 'type:conversation'
}
};
ws.send(JSON.stringify({
action: 'subscribe',
data: subscription
}));
});
ws.on('message', (data) => {
console.log('Received:', data.toString());
// Push to Kafka here
});
}
The events coming in look valid. I’m seeing JSON payloads with conversationId and type fields. But after a few hundred messages, the throughput drops to zero. I’ve tried adding a heartbeat, but that didn’t help. Is there a specific limit on message volume for this topic? Or am I missing a required header to keep the session alive? The docs aren’t super clear on the keep-alive mechanism for WebSocket subscriptions.