WebSocket disconnects after 60s silence in AppFoundry NICE Cognigy integration

We’re running a NICE Cognigy bot inside a Genesys Cloud AppFoundry microservice. The WebSocket connection to the media server drops after about 60 seconds of silence, and when it reconnects, there’s a noticeable audio lag. This is breaking the flow for our agents who are trying to track adherence metrics.

Here is the relevant part of our Node.js server code handling the connection:

const WebSocket = require('ws');

const ws = new WebSocket(process.env.GENESYS_WS_URL, {
 headers: {
 'Authorization': `Bearer ${token}`,
 'Content-Type': 'application/json'
 }
});

ws.on('open', () => {
 console.log('Connected to Genesys Media Server');
 ws.send(JSON.stringify({
 type: 'connect',
 sessionId: session.id
 }));
});

ws.on('message', (data) => {
 const msg = JSON.parse(data);
 if (msg.type === 'audio') {
 // Process audio chunk
 processAudio(msg.payload);
 }
});

ws.on('close', (code, reason) => {
 console.log(`WebSocket closed with code ${code}: ${reason}`);
 // Reconnect logic here
});

The logs show the connection closes with code 1001 (Going Away) exactly when there is no audio traffic for 60 seconds. We’ve tried adding a ping/pong mechanism, but the server seems to ignore the pings or the connection still drops before we can handle it.

Is there a specific keep-alive setting we need to configure in the AppFoundry environment or the WebSocket options? Or is this a known issue with the NICE Cognigy integration that requires a workaround in the bot logic?

Also, when the reconnect happens, the audio buffer seems to get out of sync. Any ideas on how to handle the state reset on the Genesys side?