2016-06-11 51 views

回答

3

注意:用您的值替換帳戶SID,驗證令牌,電話號碼,網站地址。

步驟1.

應答來電呼叫和記錄消息(http://somewebsite.xyz/recordMessage.php

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

<Response> 
    <Say> 
     Please leave a message at the beep. 
     Press the star key when finished. 
    </Say> 
    <Record 
     action="http://somewebsite.xyz/makeOutgoingCall.php" 
     maxLength="60" 
     timeout="10" 
     finishOnKey="*" 
     /> 
    <Say>I did not receive a recording</Say> 
</Response> 

https://www.twilio.com/docs/api/twiml/record

一旦記錄完成Twilio將使一個請求到'操作'網址,並將傳遞記錄的URL作爲名爲的參數($_REQUEST['RecordingUrl']

步驟2.

使呼出呼叫(http://somewebsite.xyz/makeOutgoingCall.php

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

<Response> 
    <Say>Thank you for your message. Goodbye.</Say> 
    <Hangup/> 
</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 = 'AC123'; 
    $token = 'abcd'; 

    // A phone number you have previously validated with Twilio 
    $phonenumber = '4151234567'; 

    $recordingUrl = urlencode($_REQUEST['RecordingUrl']); 

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

    // 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 
      '51', // The number of the phone receiving call 
      $twilioRequestUrl 
     ); 
     //echo 'Started call: ' . $call->sid; 
    } catch (Exception $e) { 
     //echo 'Error: ' . $e->getMessage(); 
    } 

https://www.twilio.com/docs/libraries/php

https://www.twilio.com/docs/quickstart/php/rest/call-request

步驟3.

播放所記錄的消息(http://somewebsite.xyz/playRecordedMessage.php)。

<?php 

    // and play the recording back, using the URL that Twilio posted 
    header("content-type: text/xml"); 
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 
?> 
<Response> 
    <Say>Take a listen to your message.</Say> 
    <Play><?php echo $_REQUEST['RecordingUrl']; ?></Play> 
    <Say>Goodbye.</Say> 
</Response> 

https://www.twilio.com/docs/quickstart/php/twiml/play-mp3-for-caller

https://www.twilio.com/docs/api/twiml/play

+0

感謝您與例如您的回覆。在步驟2中,主叫方應該正在通話。接收器應該聽到錄製的信息並與主叫方通話。刪除響應中的掛斷將工作? –

+1

您是否試圖屏幕呼叫? '接收器'是否總是與主叫方通話?如果不是,你怎麼處理來電者?請用完整的用戶故事更新您的問題。 –

+0

想要從主叫方獲得篩選問題的答案並向接收方播放答案。 –