How to find out the status of a twilio call (completed or not)

I am new to twilio api. In the web application I'm working on, I need to check the completed call or not, and I send the wav file to twiml. If this is completed, I must deduct the user's credit. I am using the following code ...

callMeAction

        $AccountSid = "**********************";
        $AuthToken = "***************";

        /* Your Twilio Number or an Outgoing Caller ID you have previously validated
          with Twilio */
        $from = '**************';

        /* Number you wish to call */
        $to = $_POST['contactno'];

        /* Directory location for callback.php file (for use in REST URL) */
        $url = 'http://'.$_SERVER['HTTP_HOST'].'/public/';

        /* Instantiate a new Twilio Rest Client */
        $client = new Services_Twilio($AccountSid, $AuthToken);



        /* make Twilio REST request to initiate outgoing call */
        $call = $client->account->calls->create($from, $to, $url . 'callback.php?number=' . $_POST['contactno'] . '&wav=' . $_POST['wav']);

        /* redirect back to the main page with CallSid */
        $msg = urlencode("Connecting... " . $call->sid);
        //header("Location: index.php?msg=$msg");

         $this->view->msg = $msg;

        if($call->status == 'COMPLETED'){

            /*
             *  Deduct credit if call completed
             */


          $this->view->msg = $msg;
        }

callback.php

<?php
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>



<?php if($_REQUEST['wav']){ ?>
<Response>
    <Say>A customer at the number <?php echo $_REQUEST['number']?> is calling</Say>
    <Dial><?php echo $_REQUEST['number']?></Dial>
    <Play><?php echo $_REQUEST['wav'] ;?></Play>
</Response>
<?php } ?>

Please help me ... Thanks in advance. :)

+5
source share
3 answers

Set the StatusCallback URL (docs halfway down this page) and put your charge logic in a script.

URL- StatusCallback , 4- : $client->account->calls->create().

URL- () ( , ).

+4

REST, - .

, , , . .

+3

URL- statuscallback , statuscallback.

URL- localhost. 00webhost , , .

For more information, please read the twilio documentation.

0
source

All Articles