Skip to main content

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:

  1. The server sends a conversation:closed event to the client.
  2. This event includes a keep_alive time window.
  3. During this window, the client can send a conversation:reopen event.
  4. If the client sends conversation:reopen, the server responds with:
    • conversation:reopened event
    • keep_alive value
    • session_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:

  1. Automatic closure: After the keep_alive time window has passed following a conversation:closed event.
  2. Manual closure: When the client sends a session:close event.
  3. 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 and session:closed are distinct events with different implications.
  • conversation:closed allows for potential reopening during the keep_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.