About the websocket
To integrate your agent into your website or mobile app, use this endpoint. You can send and receive audio in real time, which allows for seamless and natural conversations.
Step 1. Create a widget agent
In your Synthflow dashboard, create an agent of the type widget. For more details on how to do that, see Create an agent.
Step 2. Request a session
Make a GET request to the following endpoint:
It will return a response of the form:
You can then use this session URL to connect to the websocket.
Step 3. Send and receive events
Send events
You can send two types of messages through the websocket:
- Binary messages containing the user’s speech (raw PCM16 audio, sample rate of 48000).
- JSON messages (
{ "type": "status_client_ready" }
) to signal that you are ready for the agent to start speaking.
Receive events
You will receive two types of messages:
- Binary messages containing the agent’s speech (raw PC16 audio, sample rate 16000).
- JSON messages (
{ "type": "status_agent_ready" }
) that signal that the agent is ready to start receiving audio.
Writing a client
To use the websocket connection in a webpage, follow these steps: