Вопрос

I am new in twilio api. In a web application am working on, i have to check call completed or not and I am sending wav file to twiml. If completed i have to deduct credit of user.. 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. :)

Это было полезно?

Решение

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

You pass the StatusCallback URL when creating the call, you should be able to pass an array of optional parameters as the 4th argument to: $client->account->calls->create().

For incoming calls, the URL is (optionally) defined for each number (or application, if you use that method).

Другие советы

If you are making an outbound call via the REST interface, you need specify the status callback in the request parameters.

Furthermore, that callback will be asynchronous so you can't wait for the results in the calling function as you are doing in your example. You'll need to do credit management in the callback.

You should set statuscallback url in your code after you can get calling response in your statuscallback page or function.

This callback url will be not work in localhost. For the testing you should deploy your project in 00webhost after you can check it will work for you.

For the more detail Please read the twilio documentation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top