2016-11-15 125 views
0

我試圖從我的twilio試用帳戶撥打電話。我指的是link。基於這個環節上,我已創建了一個名爲頁HELLO-客戶twiml.php與下面的代碼:使用Twilio從瀏覽器撥打電話 - 呼叫自動終止

<?php 
header('Content-type: text/xml'); 

// put a phone number you've verified with Twilio to use as a caller ID number 
$callerId = "+xxxxxxxxxx"; 

// put your default Twilio Client name here, for when a phone number isn't given 
$number = "jenny"; 

// get the phone number from the page request parameters, if given 
if (isset($_REQUEST['PhoneNumber'])) { 
    $number = htmlspecialchars($_REQUEST['PhoneNumber']); 
} 

// wrap the phone number or client name in the appropriate TwiML verb 
// by checking if the number given has only digits and format symbols 
if (preg_match("/^[\d\+\-\(\) ]+$/", $number)) { 
    $numberOrClient = "<Number>" . $number . "</Number>"; 
} else { 
    $numberOrClient = "<Client>" . $number . "</Client>"; 
} 
?> 
<Response> 
    <Dial callerId="<?php echo $callerId ?>"> 
      <?php echo $numberOrClient ?> 
    </Dial> 
</Response> 

HELLO-客戶monkey.php的代碼頁:

<?php 
include "vendor/autoload.php"; 

use Twilio\Jwt\ClientToken; 

// put your Twilio API credentials here 
$accountSid = 'your_sid_here'; 
$authToken = 'your_auth_token'; 

// put your TwiML Application Sid here 
$appSid = 'APXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; 

$capability = new ClientToken($accountSid, $authToken); 
$capability->allowClientOutgoing($appSid); 
$capability->allowClientIncoming('jenny'); 
$token = $capability->generateToken(); 
?> 

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Hello Client Monkey 4</title> 
    <script type="text/javascript" 
     src="//media.twiliocdn.com/sdk/js/client/v1.3/twilio.min.js"></script> 
    <script type="text/javascript" 
     src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> 
    </script> 
    <link href="//static0.twilio.com/resources/quickstart/client.css" 
     type="text/css" rel="stylesheet" /> 
    <script type="text/javascript"> 

     Twilio.Device.setup("<?php echo $token; ?>"); 

     Twilio.Device.ready(function (device) { 
     $("#log").text("Ready"); 
     }); 

     Twilio.Device.error(function (error) { 
     $("#log").text("Error: " + error.message); 
     }); 

     Twilio.Device.connect(function (conn) { 
     $("#log").text("Successfully established call"); 
     }); 

     Twilio.Device.disconnect(function (conn) { 
     $("#log").text("Call ended"); 
     }); 

     Twilio.Device.incoming(function (conn) { 
     $("#log").text("Incoming connection from " + conn.parameters.From); 
     // accept the incoming connection and start two-way audio 
     conn.accept(); 
     }); 

     function call() { 
     // get the phone number to connect the call to 
     params = {"PhoneNumber": $("#number").val()}; 
     Twilio.Device.connect(params); 
     } 

     function hangup() { 
     Twilio.Device.disconnectAll(); 
     } 
    </script> 
    </head> 
    <body> 
    <button class="call" onclick="call();"> 
     Call 
    </button> 

    <button class="hangup" onclick="hangup();"> 
     Hangup 
    </button> 

    <input type="text" id="number" name="number" 
     placeholder="Enter a phone number to call"/> 

    <div id="log">Loading pigeons...</div> 
    </body> 
</html> 

在Twilio控制檯中,TwiML apps page,我添加了http://mywebsite.com/hello-client-monkey.php作爲語音 - >請求URL

現在,當我運行頁HELLO-客戶monkey.php,呼叫被越來越自動終止,在twilio console logs我得到的錯誤日誌中:

WARNING 
    12200 Schema validation warning 
DESCRIPTION 
Cannot find the declaration of element 'html'. 

誰能幫我解決這個問題?提前致謝。

+0

Twilio福音傳教士在這裏。看起來您需要使用'hello-client-twiml.php' URL配置您的TwiML應用程序,而不是'hello-client-monkey.php' URL。 –

+0

@Devin ...我用'hello-client-twiml.php' url配置了TwiML。但它不工作,並得到twilio控制檯日誌,如:「沒有HTTP請求記錄此事件。」 – Jenz

+0

@ DevinRader..Also我twilio號碼是美國號碼,我正在嘗試打電話給印度的手機.. 。這是對試用賬戶的限制嗎? – Jenz

回答

0

從文檔:

https://www.twilio.com/docs/api/errors/12200

架構驗證警告

提供的XML不符合Twilio標記XML架構。 請參考具體錯誤並更正問題。

可能原因

拼錯動詞,用於動詞不正確的情況下,拼錯的或未知的 屬性,未知的或意外的嵌套元素。

可能的解決方案

檢查被警告報告行和列,看看有什麼的 部分的XML響應導致投訴

正如德文以上建議,你TwiML應用程序需要twiml爲你」已經定義在hello-client-twiml.php

+0

@Megan ...我用'hello-client-twiml.php' url配置了TwiML。但它不起作用,讓twilio控制檯登錄如下:'沒有爲這個事件記錄HTTP請求.' – Jenz