Example: Answering an incoming call
This example answers an inbound Voximplant call and bridges audio to Ultravox’s WebSocket API for real‑time speech‑to‑speech conversations.
⬇️ Jump to the Full VoxEngine scenario.
Prerequisites
- Set up an inbound entrypoint for the caller:
- Phone number: https://voximplant.com/docs/getting-started/basic-concepts/phone-numbers
- WhatsApp: https://voximplant.com/docs/guides/integrations/whatsapp
- SIP user / SIP registration: https://voximplant.com/docs/guides/calls/sip
- Voximplant user: https://voximplant.com/docs/getting-started/basic-concepts/users (see also https://voximplant.com/docs/guides/calls/scenarios#how-to-call-a-voximplant-user)
- Create a routing rule that points the destination (number / WhatsApp / SIP username) to this scenario: https://voximplant.com/docs/getting-started/basic-concepts/routing-rules
- Store your Ultravox API key in Voximplant
ApplicationStorageunderULTRAVOX_API_KEY.
Session setup
Ultravox uses a WebSocket API client created via Ultravox.createWebSocketAPIClient(...). The key inputs are:
endpoint: useUltravox.HTTPEndpoint.CREATE_CALL(orCREATE_AGENT_CALLfor an existing Ultravox agent).authorizations: includeX-API-Keywith your Ultravox API key.body: providesystemPrompt,model, andvoice.
Connect call audio
Once the client is created, bridge audio both ways between the call and Ultravox:
Barge-in
Ultravox supports barge-in by providing a PlaybackClearBuffer event. If you want to interrupt the agent speech, listen for this
event and clear the media buffer with clearMediaBuffer():
The Ultravox server may also request a buffer clear via PlaybackClearBuffer — this example handles both cases.
Events
The client supports both WebSocket API events and media events. Key events used in the example:
Ultravox.WebSocketAPIEvents:Transcript,HTTPResponse,State,Debug,WebSocketError,ConnectorInformation,Unknown,PlaybackClearBufferUltravox.Events:WebSocketMediaStarted,WebSocketMediaEnded