d-api-sdk, with one option:
It works for WhatsApp calls (outbound and incoming) and for
live IVR calls. You need an already connected
unofficial WhatsApp connection and an API Key from the
Dashboard.
How it works
1
Your backend starts the call
With the API Key,
dapi.calls.stream() returns callId and wsUrl. Only
those two go to the browser, never the API Key.2
The browser opens the call
LiveCall.connect() asks for the microphone, opens the control WebSocket and
starts playing audio over it.3
The audio moves to WebRTC
In under a second the SDK negotiates WebRTC and moves the audio to it.
Events, mute and hangup stay on the WebSocket.
4
If the network blocks WebRTC
The audio goes back to the WebSocket on its own, without dropping the call,
and the SDK retries WebRTC in the background.
call.* webhooks and recordings are the same as over the WebSocket:
only the audio path changes.
Installation
@roamhq/wrtc, transport: "webrtc" keeps working over the WebSocket.
The browser needs nothing else: WebRTC is built in.
In the browser
The complete example has two parts: a route in your backend, which holds the API Key, and the page.Backend: start the call
server.js
Page: talk and listen
call.js
LiveCall.connect() from a click: browsers
only allow audio after a user action. The page must be served over HTTPS (or
localhost).
On Node (bots and AI agents)
On Node the SDK hands the raw audio to your code: PCMs16le, 16 kHz, mono,
in 20 ms frames (320 samples).
bot.js
accepted is dropped: the other side is not listening yet,
and that audio would delay the whole call. Send at real-time pace (20 ms of audio
every 20 ms); large bursts get queued and arrive late.
Receiving calls
With receiving enabled on the connection:dapi.calls.accept({ sessionId, callId, from }) and hands { callId, wsUrl } to
the page, which calls LiveCall.connect().
Live IVR calls
dtmf), audio, hangup(). The full
example, with the browser, is in Live IVR calls with WebRTC.
Events
Options
When WebRTC drops
Thetransport event tells you where the audio is going and why:
During the switch the audio pauses for a few seconds and the call goes on.
Corporate networks that block UDP stay on the WebSocket.
Migrating from the manual WebSocket
If you followed Stream Calls, Step 1 (the backend callingPOST /calls/stream) does not change. Steps 2 to 5 become one line:
call.on("event").
Other languages
The SDK speaks an open protocol on the same WebSocket aswsUrl. To implement it
in another language, with any WebRTC library:
If something fails, you get
{"type":"webrtc.error","code":"..."} with
unavailable, invalid_offer, at_capacity, gateway_error or
not_negotiated, and the audio stays on the WebSocket. Clients that never send
these messages keep working exactly as before.
Next steps
Stream Calls
The WebSocket protocol, the events and recordings.
Receive Calls
Enable receiving and answer with the SDK.
