Linking an Application Server to an IVR Node using SOAP

SOAP (Simple Object Access Protocol) is an XML message-based protocol specification used to allow applications running on a decentralized, distributed environment to exchange information. It relies on Extensible Markup Language (XML) as its message format, and usually relies on other application layer protocols, such as RPT and HTTP, for message negotiation and transmission.

Sample SOAP Message

Following is a sample data interchange using the HTTP/SOAP protocol. (The indentation shown is for illustration purposes only.)

Request

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.vodia.com/soap/pbx">
  <env:Body>
    <sns:IVRInput>
      <CallID>3525234@vodia.com</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>

In the vodia 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 and makes it possible to put the IVR input into a session context. It is also used as an identifier in the response to the request.
  • Output: The digits that the user has entered into the IVR node.
  • The To and From fields indicate the To and From headers of the call.

Response

The response on the file tells what should be done with the input. An example return could look like the following:

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.vodia.com/soap/pbx">
  <env:Body>
    <sns:IVROutput>
      <CallID>3525234@vodia.com</CallID>
      <Destination>123</Destination >
    </sns:IVROutput >
  </env:Body>
</env:Envelope>


The response has the following attributes:

  • CallID: This attribute contains the caller-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 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="";
$type="";
$domain="";
$language="";
$from="";
$to="";
$fromUser="";
$toUser="";
$chargeAccount="";
$chargeNumber="";
$timeStart="";
$timeConnected="";
$timeEnd="";
$duration="";

function start_element($parser, $name, $attrs) 
{
   global $elem;
   $elem=$name;
} 

function end_element($parser, $name) 
{} 

function xml_data($parser, $data) 
{
   global $elem,
          $callid,
          $type,
          $domain,
          $from, 
          $to,
          $fromUser,
          $toUser,
          $chargeAccount,
          $chargeNumber,
          $timeStart,
          $timeConnected,
          $timeEnd;

   if($elem=="CALLID") $callid .= $data;
   else if($elem=="TYPE") $type .= $data;
   else if($elem=="DOMAIN") $domain .= $data;
   else if($elem=="LANGUAGE") $language .= $data;
   else if($elem=="FROM") $from .= $data;
   else if($elem=="TO") $to .= $data;
   else if($elem=="FROMUSER") $fromUser .= $data;	
   else if($elem=="TOUSER") $toUser .= $data;
   else if($elem=="CHARGEACCOUNT") $chargeAccount .= $data;
   else if($elem=="CHARGENUMBER") $chargeNumber .= $data;	
   else if($elem=="TIMESTART") $timeStart .= $data;
   else if($elem=="TIMECONNECTED") $timeConnected .= $data;
   else if($elem=="TIMEEND") $timeEnd .= $data;	
} 

$content = file_get_contents("php://input");

$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); 

$fd = fopen("C:/Temp/cdr.txt", "a");
if( $fd )
{
   fwrite( $fd, "callid = $callid, \r\n 
                 type = $type, \r\n 
                 language = $language, \r\n 
                 domain = $domain, \r\n  
                 from = $from, \r\n  
                 to = $to, \r\n  
                 fromUser = $fromUser, \r\n  
                 toUser = $toUser, \r\n  
                 chargeAccount = $chargeAccount, \r\n  
                 chargeNumber = $chargeNumber, \r\n  
                 timeStart = $timeStart, \r\n  
                 timeConnected = $timeConnected, \r\n  
                 timeEnd = $timeEnd, \r\n  ";		 	

   fclose( $fd );
   echo "ok";
}
?>