We are building a custom web messaging interface for an internal tool and have decided to bypass the standard widget in favor of direct integration with the WebSocket-based Guest API. The goal is to maintain full control over the UI state and avoid the overhead of the widget bundle.
The connection logic is straightforward. We initialize the connection using the genesys-cloud-web-messaging-guest-sdk package. Here is the basic setup for establishing the socket:
const guest = new GuestSdk({
organizationId: process.env.GENESYS_ORG_ID,
deploymentId: process.env.GENESYS_DEPLOYMENT_ID,
locale: 'en-US'
});
await guest.connect();
The initial connection works as expected. We receive the connected event, and subsequent sendMessage calls return the expected ACK. However, we are running into a persistent issue during network instability testing. When the client loses connectivity and attempts to reconnect, the SDK emits a disconnected event. We catch this and call guest.connect() again.
This is where things break. The reconnection attempt fails with a session_not_found error code. The payload looks like this:
{
"code": "session_not_found",
"message": "The session associated with this client ID is no longer valid."
}
We suspect this might be related to how the clientId is persisted in the browser’s local storage. We are currently storing the clientId returned from the initial connect promise and reusing it on reconnect. Is the expectation that a new clientId should be generated for every reconnection attempt, or is there a specific lifecycle method we need to call to refresh the session token before attempting to reconnect?
We have tried clearing the local storage before reconnecting, which forces a new clientId, but this results in the user losing their conversation history and having to start a new chat, which defeats the purpose of the custom UI.
Has anyone implemented a solid reconnection strategy with this SDK? We need to preserve the conversationId and participantId across the reconnect event without triggering the session validation error.