twilio播放音乐并重定向拨号

时间:2016-08-01 15:47:40

标签: php twilio

目标:我希望在创建呼叫时它应该播放音乐而不是响铃,并且没有人可以接听电话。播放音乐之后应该说出来。 之后,它应该重定向到反馈页面

现在:当我们选择呼叫并且在拨打电话时正在运行反馈页面时,会创建呼叫并播放mp3

所以我想要一个解决方案来处理这个

<?php
  if (($nowtime >= $start_time) && ($nowtime <= $end_time)){
      $the_mnum = $con ->load_field($the_id, 'the_mnum');
      //$m= $the_mnum;
      //echo $the_mnum;
?>     <Say voice="woman"> 
        We are directing your call to the therapist.
      </Say>


<?php
      $check_therapist = true;
      $_SESSION["the_mnum"] = $the_mnum;
      break;
    }
  }

  if ($check_therapist){ 

    $version = '';
  $sid = '';
  $token = '';
  $client = new Services_Twilio($sid, $token, $version); 
  $call = $client->account->calls->create("+1", $the_mnum, "wekaw1.mp3", array());
echo $call->sid;

    ?>
 <Redirect>feedback.php</Redirect>
    <?php } else {?>
    <Say voice="woman"> 
      No listener is available right now. 
      We will give you a call back shortly when we have available listener. 
    </Say>
<?php } ?>
</Response>

1 个答案:

答案 0 :(得分:1)

要在连接2个号码之前播放保持音乐而不是铃声,您需要使用<Enqueue><Queue>组合并通过我们的Rest API发起呼叫。

以下是implementation in PHP示例。

您需要将以下文件分配给您的电话号码。此代码将<enqueue>呼叫并启动呼叫转接到您的号码。这也将启动您需要创建的第二个文件的请求(modify_leg.php)。

在某个文件中first.php:

$name = $_POST['CallSid'];

echo '<Response><Enqueue>'.$name.'</Enqueue></Response>';

// Make sure to include php-helper library
require('../Services/Twilio.php'); // Loads the library
$account_sid = 'ACxxxxxxxxxxxxxxxxx';
$auth_token = 'aaxxxxxxxxxxx';
$from_number = '+1xxxxxx';
$to_number = '+1xxxxxxxx';
$client = new Services_Twilio($account_sid, $auth_token);
$message = $client->account->calls->create($from_number, $to_number, 'http://Your-FQDN/modify_leg.php?callSid='.$name);

现在在(modify_leg.php),您将通过$_GET[callSid],这样一旦您接听电话,它将实际连接两个电话,并且来电者将听取音乐直到您实际接听电话。

<?php

$who = $_GET['callSid'];

?>
<Response>
<Dial><Queue><?php echo $who ?></Queue></Dial>
</Response>