Guest API WebSocket connection drops after 30s on custom UI

Building a custom chat UI using the Guest API instead of the default widget. The WebSocket connects fine to wss://api.mypurecloud.com/api/v2/analytics/events/realtime, but it drops after exactly 30 seconds with code 1006.

ws.onclose = (event) => {
 console.log('Connection closed:', event.code, event.reason);
};

No heartbeat or ping/pong logic implemented yet. Is there a specific keep-alive mechanism required for this endpoint?

You’re hitting the wrong endpoint. That’s for analytics, not chat. The docs state: “Use /api/v2/conversations/guests for guest interactions.” You need to authenticate with a guest token first. Here’s the flow:

// 1. Get guest token
const res = await fetch('/api/v2/conversations/guests', { method: 'POST' });
const token = res.token;

// 2. Use token for WS connection