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

  1. In your Anunzi dashboard, create an agent of the type widget.

  2. Go to Agents and select the agent you have just created. Copy the ID next to its name. This is the ID you will use as the assistant_id parameter.

Step 2. Request a session

Make a GET request to the following endpoint:

curl -X GET "https://widgets.anunzi.net/websocket/token/{assistant_id}" \
     -H "Authorization: Bearer <your-anunzi-api-key>"

It will return a response of the form:

{
  "sessionURL": "wss://widgets.anunzi.net/websocket/start?token=..."
}

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:

  1. Binary messages containing the user’s speech (raw PCM16 audio, sample rate of 48000).

  2. 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:

Write functions to record and play linear audio:

chevron-rightindex.tshashtag
chevron-rightaudio-out-worklet.jshashtag
  1. Write a function to manage the websocket connection:

chevron-rightindex.tshashtag
  1. Use the functions defined above to create a call:

chevron-rightindex.tshashtag

Última actualización