在两个未在twilio中注册的号码之间拨打电话

时间:2016-06-22 23:08:09

标签: twilio twilio-php twilio-api

有两种方法可以在我的两个用户之间拨打电话吗?我的意思是......我有一个注册号码的twilio帐户,我必须打电话给我的客户"比尔"因此,当他回答这个问题时,应该将电话重定向到比尔选择的另一个客户,让我们说#Joe;#34;。所以,比尔点击一个按钮,他的电话响了,他回答说,然后开始打电话给乔。当其中一些挂断时,所有呼叫应该结束。有人做过吗?帮我!我对自己糟糕的英语感到抱歉 (哦,是的,我正在使用php)

1 个答案:

答案 0 :(得分:4)

这只是让您前进的简单方法,您还可以查看连接到会议室https://www.twilio.com/docs/api/twiml/conference

您需要从https://www.twilio.com/docs/libraries/php#install-via-zip-file

下载 Twilio PHP Helper Library (" Services"文件夹)

项目结构

/
/Services
/callBill.php
/callJoe.php

callBill.php

<?php
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>

<Response>
    <!-- // calling Bill -->
</Response>

<?php
    // Include the Twilio PHP library
    require 'Services/Twilio.php';

    // Twilio REST API version
    $version = "2010-04-01";

    // Set our Account SID and AuthToken
    $sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

    // A phone number you have at Twilio
    $phonenumber = '5557779999';

    // The URL Twilio will request when the call is answered            
    $twilioRequestUrl = "http://somewebsite.xyz/callJoe.php";

    // Instantiate a new Twilio Rest Client
    $client = new Services_Twilio($sid, $token, $version);

    try {

        // Initiate a new outbound call
        $call = $client->account->calls->create(
            $phonenumber, // The number of the phone initiating the call
            '7779995555', // call Bill at 7779995555
            $twilioRequestUrl 
        );
        //echo 'Started call: ' . $call->sid;
    } catch (Exception $e) {
        //echo 'Error: ' . $e->getMessage();
    }

?>

callJoe.php

<?php

    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>

<!-- call and connect Joe at 9995557777 -->
<Response>
    <Pause length="2"/>
    <Say>Please wait, I'm calling Joe.</Say>
    <Dial>9995557777</Dial>
</Response>

使用浏览器或点击按钮请求http://somewebsite.xyz/callBill.php