WebSocket drops on AppFoundry Cognigy integration despite valid OAuth

We’ve got an AppFoundry app that bridges Genesys Cloud WebSockets to a NICE Cognigy bot. The connection starts fine, but it drops every 30-60 seconds. We’re using the JS SDK to handle the WebSocket events. Here’s the init code:

const ws = new WebSocket(`wss://api.mypurecloud.com/api/v2/analytics/conversations/events`);
ws.onmessage = (event) => {
 const data = JSON.parse(event.data);
 injectOtelContext(data); // Custom tracing hook
 forwardToCognigy(data);
};

The logs show the connection closing with code 1006 (abnormal closure) right after the first batch of spans is sent. We’ve verified the OAuth token is valid and has the right scopes. It seems like the server is killing the connection when the payload size crosses a certain threshold or maybe due to rate limiting on the event stream. Has anyone seen this with Cognigy integrations? We’re trying to keep the tracing context alive across the bot flow. The latency spikes before the drop are around 800ms, which is way too high for a real-time bot. We’re running this in an AWS Lambda behind API Gateway, could that be the issue? We’ve tried increasing the keep-alive interval but it didn’t help. Any ideas on how to stabilize the connection without losing the trace context?