twilio呼叫Api <say> </say>无效

时间:2014-08-13 09:41:10

标签: php twilio

嗨,伙计们我正在尝试使用twilio拨打电话,我希望如果正在接听电话然后播放录音或将文本转换为语音,我在Twiml <say></say>我的代码中提供该号码以获取该号码在输入中调用是

`

<htmL>
<body>
      <h1>Click-to-call</h1>
          <?php 

         if(isset($_REQUEST['msg'])) {
           echo '<i>' . $_REQUEST['msg'] . '</i>';
         }

        ?>
<h3>Please enter your phone number, and you will be connected to </h3>
      <form action="makecall.php" method="post">
            <span>Your Number: <input type="text" name="called" /></span>
            <input type="submit" value="Connect me!" />
      </form>
</body>
</html>

` 并且callback.php如下

`

<?php
require "Services/Twilio.php";


$AccountSid = "xxxxxxxxxxxxxxxxxxxxxxx";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxx";

$from= '+91xxxxxxxxxx';

$to= '+91xxxxxxxxxx';

$url = 'http://example.com/play.xml';

$client = new Services_Twilio($AccountSid, $AuthToken);

if (!isset($_REQUEST['called']) || strlen($_REQUEST['called']) == 0) {
        $err = urlencode("Must specify your phone number");
        header("Location: index.php?msg=$err");
       die;
}


        $call = $client->account->calls->create($from, $to, $url );


$msg = urlencode("Connecting... ".$call->sid);
header("Location: index.php?msg=$msg");
?>

` 但是,当我接到电话时,它不会播放或说出在twiML下写的任何内容。 请帮帮我

我的TwiML代码如下

`

<Response>
    <Say voice="alice">Thanks for the call. Configure your number's voice U R L to change this message.</Say>
</Response>

`

2 个答案:

答案 0 :(得分:1)

通过更新“从以下内容”

解决了这个问题

$call = $client->account->calls->create($from, $to, $url );

$call = $client->account->calls->create($from, $to,$url, 
       array( 
           'Method' => 'GET',  
           'FallbackMethod' => 'GET',  
           'StatusCallbackMethod' => 'GET',    
           'Record' => 'false', 
           ));

由于数组正在指示如何访问链接。

答案 1 :(得分:0)

嗨Twilio福音传教士,

您可以查看account logs来查看Twilio要求的网址吗?

我不是最好的PHP开发人员,但我认为这两行:

$url = 'http://example.com/play.xml';
$call = $client->account->calls->create($from, $to, $url . 'callback.php?number=' .            $_REQUEST['called']);

..导致您的网址为:

http://example.com/play.xml

否则,你也可以发布你的TwiML代码吗?另一种可能性 - 检查TwiML是否正确套装,所有TwiML动词都有一个大写字母。所以无效

<Response>
    <say>hello</say>
</Response>

工作:

<Response>
    <Say>hello</Say>
</Response>

希望这有帮助。