Skip to main content
The Voiceflow WebSocket runtime uses socket.io to establish persistent, bidirectional connections for real-time conversational AI interactions. Find the socket.io client in your respective development language. This documentation will use javascript, but the fundamentals remain the same.

Connection configuration

socket.io allows for fallback transports if the end-client does not allow the websocket protocol (wss://), common in many firewalls and enterprise settings.

Lifecycle

A session is not the same as the socket.io connection. You can disconnect/reconnect multiple times and still continue the same conversation session.
For more information on socket.io lifecycle management, reference documentation.

Initialization sequence

  1. Wait for connect. This is a socket.io level connection established.
  2. Send client.start. Send voiceflow project metadata/config + optional sessionKey.
  3. Wait for client.started. Client handshake, confirms configuration.
  4. If client.started specifies newSessionRequired:
    1. Send session.create.
    2. Wait for session.created. Save returned sessionKey for future use.
  5. Agent is now ready for interactions

Action Lifecycle

Once the session is ready, you can now send actions to the agent and get responses back.
  1. send new action with action.send, i.e. { type: 'text', payload: 'hello' }
  2. get back a status action.status either status: 'accepted' | 'rejected'
  3. if status: accepted:
    1. get back agent responses with action.trace, display to user
    2. get action.status with status: 'completed'
This represents the back and forth conversation with the agent.
Try to not send a new action while an existing action is running. While this is supported, it can make it harder to debug user state and lead to certain race conditions.Instead wait for status: 'completed' or status: 'rejected' after sending an action.

Conversation Lifecycle

Start

To start the conversation from the beginning, your first action should be:
It is also possible to launch from specific points in the conversation with events:

End

The session ending also signals that the conversation has ended. This can also occur because of timeouts.

Client events

client.start

Initial Voiceflow metadata and configuration to validate and set up the client. This is aways the first message that the client should send to the server after socket.io successfully connects. Server will respond with client.started.

Payload

?: denotes optional properties.

Example Call

session.create

Creates a new session for the user. Should be sent after client.started indicates newSessionRequired: true. Server will respond with session.created.

Example Call

action.send

Sends a user action to the server. A valid session must already exist. Server will respond with action.status and action.trace events. See possible action types in the action body of interaction requests..

Payload

Example Call

Server events

client.started

Server ack to client.start, informs if a new session needs to be created

Payload

Example

session.created

Confirms that a new session has been created. Client should store the sessionKey for future reconnections.

Payload

Example

session.ended

Indicates that the conversation session has ended. Client should close the session and optionally display a workflow to create a new one.

Payload

action.trace

Represents agent responses and debugging information for an action. See possible trace types.

Payload

Example

action.status

Indicates the status of an action that was sent via action.send. This event is sent when an action is accepted, rejected, or completed.

Payload

server.restart

Server is gracefully shutting down and informing the client to reconnect to a different server instance.

Payload

error

General error message from the server. May occur at any point during the connection.

Payload