我已经设置了一个twilio号码。当有来电时,呼叫者会收到欢迎信息,然后呼叫转发到我的手机。如果呼叫未应答,则呼叫转到语音邮件消息,告诉呼叫者留言,呼叫转到语音邮件。一切正常。 但如果电话接听,我挂机,流程就不会停止。它继续语音邮件消息。现在我的问题是:
当通话结束时,如何停止流程?
这是我的代码:
<?php
header('content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Play>http://example.com/telephone/sounds/welcome-message.mp3</Play>
<Dial record="true" timeout="25">
<Number url="http://example.com/telephone/wisper.php">
+4581732211
</Number>
</Dial>
<Play>http://example.com/telephone/sounds/no-answer.mp3</Play>
<Record transcribe="true" transcribeCallback="http://twimlets.com/voicemail?Email=mail@mydomain.com"/>
</Response>
答案 0 :(得分:1)
在您的代码中,Dial和Record都发生在同一个TwiML文件中。所以条件执行是不可能的。
解决这个问题,
1.将录制部分移动到另一个文件。 (说recording.php
)
2.然后在拨号期间将新文件的URL(recording.php
)指定为操作。拨号完成后,twilio将向此URL发出请求,并且将继续执行从此URL收到的TwiML。
3.检查DialCallStatus
中的值请求参数recording.php
。如果已应答已拨电话,则值为completed
或answered
(如果是会议)。在recording.php
<强> dial.php 强>
<?php
header('content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Play>http://example.com/telephone/sounds/welcome-message.mp3</Play>
<Dial record="true" timeout="25" action="http://example.com/telephone/recording.php">
<Number url="http://example.com/telephone/wisper.php">
+4581732211
</Number>
</Dial>
</Response>
<强> recording.php 强>
<?php
header('content-type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$dial_call_status = $_REQUEST['DialCallStatus'];
if($dial_call_status == "completed" || $dial_call_status == "answered"){
?>
<Response>
<Hangup/>
</Response>
<?php
}else{
?>
<Response>
<Play>http://example.com/telephone/sounds/no-answer.mp3</Play>
<Record transcribe="true" transcribeCallback="http://twimlets.com/voicemail?Email=mail@mydomain.com"/>
</Response>
<?php
}
?>