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:closed
event to the client. - This event includes a
keep_alive
time window. - During this window, the client can send a
conversation:reopen
event. - If the client sends
conversation:reopen
, the server responds with:conversation:reopened
eventkeep_alive
valuesession_id
status: '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_alive
time window has passed following aconversation:closed
event. - Manual closure: When the client sends a
session:close
event. - Session expiration: When the
session_timeout
time 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:expired
message.
session:close
event
{
"session_id": "123e4567-e89b-12d3-a456-426614174000",
"timestamp": 123123113
}
Important notes
conversation:closed
andsession:closed
are distinct events with different implications.conversation:closed
allows for potential reopening during thekeep_alive
window.session:closed
is final and cannot be reopened.- Once a session is closed, it is permanently expired and cannot be used for further communication.