- Node.js v18 LTS
@genesyscloud/purecloud-platform-client-v2SDK- HashiCorp Vault for secret storage
- AWS Lambda runtime
Is it possible to implement a robust reconnection strategy for the Genesys Cloud Notification API WebSocket client that respects both the platform’s backoff policies and our internal secret rotation schedules?
I am building a service that listens to /api/v2/analytics/events for real-time queue updates. The current implementation uses the official SDK to establish the connection. However, when the underlying WebSocket drops due to network instability or a forced client secret rotation in Vault, the default SDK reconnection behavior seems to fail silently or exhaust retries too quickly.
Here is the core connection setup:
const PureCloudPlatformClientV2 = require('@genesyscloud/purecloud-platform-client-v2');
const setup = new PureCloudPlatformClientV2.Setup();
setup.init(
process.env.CLIENT_ID,
process.env.CLIENT_SECRET, // Rotated via Vault
process.env.API_ENVIRONMENT,
process.env.ORGANIZATION_ID
);
const notificationClient = new PureCloudPlatformClientV2.NotificationClient();
notificationClient.connect({
subscriptions: [
{
topic: '/api/v2/analytics/events',
filter: { query: 'event.type=="queueEvent"' }
}
]
}).then(() => {
console.log('WebSocket connected');
}).catch((err) => {
console.error('Connection failed:', err);
});
The issue arises when CLIENT_SECRET is rotated in Vault. The active WebSocket connection remains open until a keep-alive failure, resulting in a 401 Unauthorized on the next message or a generic disconnect. I need to handle the re-authentication gracefully without dropping the subscription state.
I have tried:
- Catching the
errorevent on the WebSocket and manually callingnotificationClient.connect()with refreshed credentials. This results in duplicate subscriptions or errors. - Using the
reconnectoption in the SDK, but it does not seem to support injecting a new token before the reconnect attempt.
How should I structure the reconnection logic to ensure that after a secret rotation, the client fetches a new OAuth token and re-subscribes cleanly without losing the event stream? I am looking for a pattern that integrates well with an async secret retrieval function.