Linking External Application Server to an IVR Node
From Pbxnsip Wiki
SOAP Format
The data interchange is done by using the HTTP/SOAP protocol. When the PBX has enough information to start a request, it will generate a SOAP request that has the following format. The real file will not have indentation; here it is only for illustration purposes.
POST /ivr.xml HTTP/1.1
Host: pbx.com
SOAPAction: IvrInput
Content-Type: application/xml
Content-Length: 123
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sns="http://www.pbxnsip.com/soap/pbx">
<env:Body>
<sns:IVRInput>
<CallID>3525234@pbxnsip.cim</CallID>
<Output>123</Output>
<From>Fred Feuerstein <sip:ff@test.com></From>
<To>Tom Test <sip:tt@test.com></To>
</sns:IVRInput>
</env:Body>
</env:Envelope>
The format follows the SOAP specification. In the pbxnsip namespace, the record CDR indicates that a CDR shall be transmitted. The CDR may have the following attributes:
- CallID: This attribute contains the call-ID of the call. It makes it possible to put the IVR input into a session context. It is also used as identifier in the response to the request.
- Output: The digits that the user has entered in the IVR node.
- The To and From fields indicate the To and From headers of the call.
The return on the file contains the answer what to do with the input.
An example return could look like this:
HTTP/1.1 200 Ok
Content-Type: application/xml
Content-Length: 123
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sns="http://www.pbxnsip.com/soap/pbx">
<env:Body>
<sns:IVROutput>
<CallID>3525234@pbxnsip.com</CallID>
<Destination>123</Destination >
</sns:IVROutput >
</env:Body>
</env:Envelope>
The response has the following attributes:
- CallID: This attribute contains the call-ID of the call. It is used to identify the affected call.
- Destination: This string indicates which account to switch to.
Example PHP File
This code example shows how to process the CDR on an Apache web server using the PHP extension. This example just extracts the data and writes it into a plain file.
<?php
$elem="";
$callid="";
$output="";
function start_element($parser, $name, $attrs) {
global $elem;
$elem=$name;
}
function end_element($parser, $name) {
}
function xml_data($parser, $data) {
global $elem, $from_user, $to_user, $from, $to, $duration, $start, $callid, $output;
if($elem=="CALLID") $callid .= $data;
else if($elem=="OUTPUT") $output .= $data;
}
$content = $HTTP_RAW_POST_DATA;
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "start_element", "end_element");
xml_set_character_data_handler($xml_parser, "xml_data");
if(!xml_parse($xml_parser, $content, true)) {
die(sprintf("Get XML error parsing %s: %s at line %d",
htmlspecialchars($content),
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
xml_parser_free($xml_parser);
// Ok here some bogus logic what to do with the input:
$result = "123";
$xml = '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sns="http://www.pbxnsip.com/soap/pbx">';
$xml .= '<env:Body><sns:IVROutput><CallID>';
$xml .= $callid;
$xml .= '</CallID><Destination>';
$xml .= $result;
$xml .= "</Destination></sns:IVROutput></env:Body></env:Envelope>\r\n";
echo $xml;
?>
