Skip to content

Conversation

@bigO68
Copy link

@bigO68 bigO68 commented Oct 9, 2025

Amazon Connect Chat: Enhanced End Chat Flow Implementation

Problem Statement
The original "End Chat" button immediately terminated the WebSocket connection after calling disconnectParticipant(), preventing customers from receiving post-disconnect messages like surveys or farewell notifications.

Solution Overview
Maintain the WebSocket connection after disconnectParticipant() API call, allowing the chat to remain active until the server sends a chatEnded event.

Key Technical Changes

  1. Deferred Connection Termination
    Removed immediate cleanup from disconnectParticipant() method
    Moved connection termination logic to _handleIncomingMessage() when CONTENT_TYPE.chatEnded is received

  2. State Management Refactoring
    // Before: Immediate cleanup in disconnectParticipant()
    this._participantDisconnected = true;
    this.hasChatEnded = true;
    this.cleanUpOnParticipantDisconnect();
    this.breakConnection();

// After: Server-driven cleanup in _handleIncomingMessage()
if (incomingData.ContentType === CONTENT_TYPE.chatEnded) {
this.hasChatEnded = true;
this._forwardChatEvent(CHAT_EVENTS.CHAT_ENDED, {
data: null,
chatDetails: this.getChatDetails()
}, () => {
this._participantDisconnected = true;
this.cleanUpOnParticipantDisconnect();
});
this.breakConnection();
}

  1. Event Ordering Fix
    Used callback pattern in _forwardChatEvent() to ensure CHAT_ENDED event is published before cleanup
    Prevents race conditions between UI notifications and connection termination

@bigO68 bigO68 requested a review from a team as a code owner October 9, 2025 21:31
@bigO68 bigO68 requested review from doreechi and palna26 and removed request for a team October 9, 2025 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants