Example: Placing an outbound call
Example: Placing an outbound call
For the complete documentation index, see llms.txt.
This example starts a VoxEngine session, places an outbound PSTN call, and bridges audio to Inworld Realtime once the callee answers.
Jump to the Full VoxEngine scenario.
Prerequisites
- Create a routing rule with this scenario attached so you can run it from the Control Panel or trigger it with the Management API.
- Have a PSTN
destinationnumber you can dial. - Configure a valid outbound
callerId, such as a rented Voximplant number or a verified caller ID. See Phone Numbers & PSTN. - Store your Inworld API key in Voximplant Secrets under
INWORLD_API_KEY.
Outbound call parameters
The example expects destination and callerId in customData passed to the routing rule:
Launch the routing rule
For quick testing from the Voximplant Control Panel:
- Open your Voximplant application and go to the Routing tab.
- Select the routing rule that has this scenario attached.
- Click Run.
- Provide custom data JSON with
destinationandcallerId.
For production, start the routing rule via the Management API startScenarios method and pass the same JSON in script_custom_data.
Alternate outbound destinations
This example uses VoxEngine.callPSTN(...) for PSTN dialing. You can also route outbound calls to other destination types in VoxEngine:
- SIP (
VoxEngine.callSIP): dial a SIP URI to reach a PBX, carrier, SIP trunk, or other SIP endpoint. - WhatsApp (
VoxEngine.callWhatsappUser): place a WhatsApp Business-initiated call from an enabled WhatsApp Business number. - Voximplant users (
VoxEngine.callUser): call another app user inside the same Voximplant application, such as a Web SDK, mobile SDK, or SIP user.
Relevant guides:
Session setup
Outbound setup follows this order:
- Parse
destinationandcallerIdfromVoxEngine.customData(). - Place the PSTN call with
VoxEngine.callPSTN(...). - Wait for
CallEvents.Connected. - Create
Inworld.RealtimeAPIClient. - Send the same style of
sessionUpdate(...)payload shown in the inbound example after Inworld emitsSessionCreated. - Bridge call media to Inworld after
SessionUpdated. - Seed the first assistant turn with
conversationItemCreate(...)andresponseCreate(...).
The scenario deliberately creates and configures the Inworld session only after the callee answers, so the agent does not speak into ringback:
The full outbound scenario keeps the session config intentionally smaller than the inbound example: it sets the model, prompt, audio input/output models, and the TTS delivery options used by this call flow. For the detailed session config walkthrough, including naturalness and responsiveness tuning, see Answering an incoming call.
After SessionUpdated, connect the PSTN leg to Inworld and trigger the opening turn:
For provider-specific tuning details, see Inworld’s Realtime API Extensions.
The example also adds:
CallEvents.FailedandCallEvents.Disconnectedhandlers for cleanup.- A demo hangup timer to avoid indefinitely running sessions.
- Inworld event logs for session updates, response lifecycle, transcripts, speech starts, and errors.
Barge-in
Callee speech clears queued Inworld output audio so the callee can interrupt the agent naturally:
Notes
INWORLD_API_KEYis read from Voximplant Secrets.sessionKeycan be any unique string to maintain context for the Inworld session.- The example includes a demo hangup timer so unattended outbound tests do not run indefinitely.