PHP IVR API | Simple Gateway API

Back to PHP Interface

  1. call_ivr
  2. call_status_response
  3. Source Code

Call IVR

Synopsis - call_ivr

call_ivr <phoneno> <appname> <selfdelete> <callerid> <detection>

Description - call_ivr

Objective

Make a phone call to the specified number and use the IVR application to interact and control the phone call.

Parameters
<phoneno> The phone number to call.
<appname> The name of the deployed IVR application.
<selfdelete> Ask the gateway to automatically delete the call request after the call is made if it is set to '1';
<callerid> The 11 digit caller ID number.
<detection> The amount of detection for our system to recognize human answer. 0= balanced, 1= more aggressive, 2= most aggressive, 3= detection off.
Returns
<reqId> The return value is the call request ID.

Example - call_ivr


                        call_ivr('123-4567', 'reminderApp', 1, '12345678911', 1);
                    

Call Status Responses

Synopsis - call_status_response

call_status_responses <reqId> <responses>

Description - call_status_response

Objective

Check the call status and responses of the call with reqId. The second parameter is a reference to an array and is used to collect responses. So if you have an element named AttendMeeting, the response can be accessed as responses["AttendMeeting"]. Please note that you can have multiple IVR elements that collect responses.

Parameters
<reqId> The reqId.
<responses> Reference to an array and is used to collect responses.

Example - call_status_response


                        $responses = array();
                        $status = call_status('11234035434', $responses)
                    

Source Code


                        class Voicent
                        {
                        var $host = "localhost";
                        var $port = 8155;

                        ...

                        function call_ivr($phoneno, $appname, $selfdelete)
                        {
                        $body = "info=" . urlencode("call " . $phoneno) . "&";
                        $body .= "phoneno=" . urlencode($phoneno) . "&";
                        $body .= "firstocc=10&";
                        $body .= "startapp=" . urlencode($appname) . "&";
                        $body .= "selfdelete=" . $selfdelete;

                        return $this->_call_now($body);
                        }

                        function call_status_response($reqId, &$responses)
                        {
                        $headers = "GET /ocall/callstatusHandler.jsp?reqid=" . $reqId . " HTTP/1.1\r\n" .
                        "User-Agent: Mozilla/4.0\r\n" .
                        "Host: " . $this->host . "\r\n" .
                        "\r\n";

                        if (! ($sock = fsockopen($this->host, $this->port, $errno, $errstr))) {
                        echo $errstr;
                        return false;
                        }

                        fwrite($sock, $headers, strlen($headers));

                        $status = "";
                        while ($line = fgets($sock, 4096)) {
                        if ($line == '')
                        continue;
                        $rcarr = explode("^", $line);

                        // call responses is the 9th field
                        $resparr = explode("|", $rcarr[8]);
                        foreach ($resparr as $resp) {
                        // each is a name value pair
                        $nvarr = explode("=", $resp);
                        $key = $nvarr[0];
                        $value = $nvarr[1];
                        $responses[$key] = $value;
                        }

                        // call status is the 3rd field
                        if ($rcarr[2] == "made")
                        $status = "Call Make";
                        if ($rcarr[2] == "failed")
                        $status = "Call Failed";
                        break;
                        }

                        fclose($sock);
                        return $status;
                        }

                        ......
                        }