Stuck on programmatic wrap-up code assignment in a custom Electron desktop client.
Context:
I am building a desktop app using Electron that embeds the Genesys Cloud WebRTC softphone. The renderer process handles UI, while the main process manages the @genesys/cloud-sdk and system tray state. When an interaction ends, I attempt to set the wrap-up code via the conversationsInteractions API before the conversation fully terminates to ensure audit compliance. I am using the postConversationsInteractionsInteractionIdWrapup endpoint. The code looks like this:
const wrapupCode = '900';
await sdkClient.conversationsInteractions.postConversationsInteractionsInteractionIdWrapup(interactionId, {
wrapupCode,
reason: 'Customer satisfied'
});
However, I consistently receive a 409 Conflict response with the message "interaction_already_ended". The interaction status transitions to TERMINATED almost immediately after disconnect(), leaving a very narrow window for the API call. I have tried delaying the call with setTimeout, but it feels like a race condition hack rather than a robust solution.
Question:
Is there a specific sequence or event listener in the SDK that guarantees the interaction is in a WRAPUP state before I can post the code? Or should I be using a different endpoint, perhaps updating the interaction via patchConversationsInteractionsInteractionId instead? The documentation is sparse on the exact state machine transitions required for programmatic wrap-up.