Closing a session
There are several ways a WebSocket session can be closed, each with different implications and behaviors. This document explains the different scenarios and their associated events. For more information about sessions, refer to the sessions lifecycle page.
Types of session closure
Conversation closure by agent
When a human agent or a resolve response closes the conversation, the following sequence occurs:
- The server sends a
conversation:closedevent to the client. - This event includes a
keep_alivetime window. - During this window, the client can send a
conversation:reopenevent. - If the client sends
conversation:reopen, the server responds with:conversation:reopenedeventkeep_alivevaluesession_idstatus: 'open'timestamp
conversation:closed event
{
"keep_alive": 300, // 5 minutes
"session_id": "123e4567-e89b-12d3-a456-426614174000",
"status": "closed",
"timestamp": 123123113,
// Only if the conversation is closed by a human agent
"agent_id": "123e4567-e89b-12d3-a456-426614174000",
"agent_name": "John Agent"
}
conversation:reopened event
{
"session_id": "123e4567-e89b-12d3-a456-426614174000",
"status": "open",
"timestamp": 123123113
}
Session closure
A session can be closed in the following ways:
- Automatic closure: After the
keep_alivetime window has passed following aconversation:closedevent. - Manual closure: When the client sends a
session:closeevent. - Session expiration: When the
session_timeouttime window has passed.
In every case, the server emits a session:closed event. After this event:
- The session is immediately expired.
- Any subsequent requests related to the session will return a
session:expiredmessage.
session:close event
{
"session_id": "123e4567-e89b-12d3-a456-426614174000",
"timestamp": 123123113
}
Important notes
conversation:closedandsession:closedare distinct events with different implications.conversation:closedallows for potential reopening during thekeep_alivewindow.session:closedis final and cannot be reopened.- Once a session is closed, it is permanently expired and cannot be used for further communication.