Developers

Programmable Voice API

Use XML response verbs to program real-time call behavior for inbound and outbound voice workflows. This guide follows the official API model with clearer language and examples.


How It Works

Your application initiates or modifies a call through REST API endpoints and provides either a URL to an XML response document or an inline XML payload. NextGenSwitch executes each XML verb in order.

Example XML response:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Say>Hello, world!</Say>
</Response>

PHP helper example:

<?php
require_once './vendor/autoload.php';
use NextGenSwitch\VoiceResponse;

$response = new VoiceResponse();
$response->say('Hello World!');

echo $response->xml();

Available XML Verbs

  • <SAY> - Convert text to speech.
  • <PLAY> - Play audio media.
  • <GATHER> - Collect DTMF and/or speech input.
  • <DIAL> - Connect to another party or channel.
  • <RECORD> - Capture caller audio.
  • <STREAM> - Start bidirectional WebSocket audio streaming.
  • <HANGUP> - End the active call.
  • <PAUSE> - Pause flow for a configured duration.
  • <REDIRECT> - Load another XML instruction document.
  • <BRIDGE> - Bridge to another in-progress call.
  • <LEAVE> - Exit queue/waiting context but keep call alive.

Create or Modify Calls via API

Use a REST request from your application to trigger or modify call behavior.

Create Call (POST)

Required request parameters:

Parameter Description
toDestination number for the call.
fromCaller number or client identifier.
statusCallback (optional)Webhook URL for live states such as dialing, ringing, established, and disconnected.
responseURL to XML instruction document (omit if using responseXml).
responseXmlInline XML instruction body (omit if using response URL).
curl --header "X-Authorization: Your_authorizaton_code" \
  --header "X-Authorization-Secret: Your_authorizaton_secret" \
  --request POST \
  --data 'to=23123&from=2323&statusCallback=http://your_status_callback_url&response=http://your_xml_response_document_url' \
  http://nextgenswitch_url/api/v1/call

Modify Ongoing Call (PUT)

Send a PUT request with call_id and responseXml to change the active call flow.

Endpoint:

PUT http://nextgenswitch_url/api/v1/call/{call_id}

Required parameters:

Parameter Description
call_idUnique ID of the active call to modify.
responseXmlInline XML containing updated flow instructions.
curl --header "X-Authorization: Your_authorizaton_code" \
  --header "X-Authorization-Secret: Your_authorizaton_secret" \
  --request PUT \
  --data '"responseXml": "<Response>\n  <Pause length=\"2\"/>\n  <Say loop=\"1\">call has been modified</Say>\n  <Dial>1000</Dial>\n</Response>"' \
  http://nextgenswitch_url/api/v1/call/{call_id}

<Say> Verb

Converts text to speech for playback during the call.

AttributeDescription
loopNumber of repetitions. A value of 0 can be treated as continuous looping by implementation.
<Response>
    <Say loop="2">This message will be repeated twice.</Say>
</Response>

<Play> Verb

Plays an audio file from URL or supported media source.

AttributeDescription
loopNumber of repetitions. Values less than or equal to 0 may be treated as extended looping.
<Response>
    <Play loop="3">https://example.com/audio/connecting.mp3</Play>
</Response>

<Gather> Verb

Collects user input by DTMF, speech recognition, or both.

AttributeDescription
actionWebhook URL for collected input.
methodHTTP method for action URL (`POST`/`GET`).
timeoutWait time for input in seconds.
speechTimeoutSpeech input wait time in seconds.
numDigitsExpected DTMF length; `0` waits for timeout or finish key.
finishOnKeyDTMF key that finalizes input.
actionOnEmptyResultWhether to call action URL with empty input.
transcriptEnable speech transcription.
beepPlay beep before capture starts.
speechProfileCustom speech-recognition profile.
inputInput mode: `dtmf`, `speech`, or `dtmf speech`.
<Gather action="https://example.com/process_input" method="POST" maxDigits="4" timeout="10">
    <Say>Please enter your 4-digit PIN.</Say>
</Gather>

<Dial> Verb

Connects the current call to a phone number, queue, or external SIP/VoIP destination.

AttributeDescription
toTarget phone number, SIP endpoint, or queue name.
actionWebhook URL called after dial completes.
methodHTTP method for action webhook.
callerIdCaller ID for outbound leg.
answerOnBridgeBridge audio immediately after answer.
ringToneEnable/disable ringback tone to caller.
timeLimitMaximum connected call duration in seconds.
hangupOnStarAllow caller to hang up by pressing `*`.
recordRecording mode (`record-from-answer` / `record-from-ringing`).
recordingStatusCallbackRecording event webhook URL.
statusCallbackCall status event webhook URL.
channelAdvanced channel selector.
channel_idAdvanced numeric channel identifier.
<Response>
    <Dial to="+1234567890" answerOnBridge="true" record="record-from-answer">
        <Play>https://example.com/audio/connecting.mp3</Play>
    </Dial>
</Response>

<Record> Verb

Records caller audio with optional timeout, key-based stop, beep, and transcription support.

AttributeDescription
actionWebhook URL receiving recording metadata and file reference.
methodHTTP method for action URL.
timeoutSeconds of silence before auto-stop.
finishOnKeyKey to end recording (set 0 to disable key stop).
transcribeEnable transcription output.
trimTrim leading/trailing silence.
beepPlay beep before recording starts.
<Response>
    <Record
        action="https://example.com/handle_recording"
        method="POST"
        timeout="5"
        finishOnKey="#"
        beep="true" />
</Response>

<STREAM> Verb

Creates a live, bidirectional audio stream over WebSocket for AI agents or custom real-time services.

<?xml version="1.0"?>
<response>
  <connect>
    <stream name="stream" url="ws://127.0.0.1:8766/ws">
      <parameter name="param1" value="param1_value" />
      <parameter name="param2" value="param2_value" />
    </stream>
  </connect>
</response>

<Hangup> Verb

Immediately disconnects the active call.

<Response>
    <Say>We are now going to hang up.</Say>
    <Hangup />
</Response>

<Pause> Verb

Temporarily pauses call execution for the defined duration.

<Response>
    <Pause length="3" />
    <Say>Your call is very important to us.</Say>
</Response>

<Redirect> Verb

Stops current execution and loads a new XML instruction document from the specified URL.

<Response>
    <Say>You will now be redirected to a different set of instructions.</Say>
    <Redirect method="GET">https://example.com/new_instructions.xml</Redirect>
</Response>

<Bridge> Verb

Bridges the active call with another in-progress call using a bridge call ID.

AttributeDescription
bridgeAfterEstablish Boolean flag controlling bridge timing: false attempts immediate bridge, true waits until secondary call is fully established.
<Response>
    <Say>We are bridging your call now.</Say>
    <Bridge bridgeAfterEstablish="true">ABC123</Bridge>
</Response>

<Leave> Verb

Removes the caller from queue/conference context while continuing the call flow.

<Response>
    <Say>You will now leave the queue, but remain on the call.</Say>
    <Leave />
    <Say>Welcome back! You have left the queue.</Say>
</Response>