Connection configuration
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.
Initialization sequence
- Wait for
connect. This is a socket.io level connection established. - Send
client.start. Send voiceflow project metadata/config + optionalsessionKey. - Wait for
client.started. Client handshake, confirms configuration. - If
client.startedspecifiesnewSessionRequired:- Send
session.create. - Wait for
session.created. Save returnedsessionKeyfor future use.
- Send
- 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.- send new action with
action.send, i.e.{ type: 'text', payload: 'hello' } - get back a status
action.statuseitherstatus: 'accepted' | 'rejected' - if
status: accepted:- get back agent responses with
action.trace, display to user - get
action.statuswithstatus: 'completed'
- get back agent responses with
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: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.