We are implementing custom typing indicators and read receipts for our self-service web widget using the Genesys Cloud Web Messaging Guest API. The documentation suggests using a simple POST to /api/v2/conversations/messaging/guest/participants/{participantId}/typing with a JSON body containing "isTyping": true.
The implementation works intermittently. When the user types rapidly, we receive 400 Bad Request errors with the message "Invalid typing state transition." It appears the API does not like consecutive true states or rapid toggles. We have tried adding a debounce function in the frontend JavaScript, but the race condition persists if the user stops typing and starts again quickly.
Is there a recommended way to batch these updates or check the current state before posting? We want to avoid flooding the API with requests, but we also need the typing indicator to be responsive for the agent. The current code looks like this:
async function sendTypingStatus(isTyping) {
await fetch(`${baseUrl}/participants/${participantId}/typing`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ isTyping: isTyping })
});
}
The error response payload is minimal, which makes debugging difficult. We are running the latest version of the SDK in a Next.js environment. Any insights on handling these state transitions correctly would be helpful.