dtnpf35197 2017-07-06 15:29
浏览 91

Twilio传出的浏览器呼叫断开连接

I'm using Twilio Outgoing Browser Calls in my project. The twiml to make call is like this :

<Response>
    <Dial action="hold_twiml.php" callerId="xxxxxxxxxx">
          xxxxxxxxxx
    </Dial>
</Response>

hold_twiml.php

if ( $_REQUEST['DialCallStatus'] == 'completed' ) { ?>
<Response>
    <Hangup/>
</Response>
<?php
}
else {
?>
<Response>
    <Play>http://demo.twilio.com/docs/classic.mp3</Play>
    <Redirect>hold_twiml.php</Redirect>
</Response>
<?php
}
?>

I want to disconnect the call when the call ends from client/browser. For that I've added the if ( $_REQUEST['DialCallStatus'] == 'completed' ) condition and now the call is getting ended from both sides. But now the Hold feature is not working properly. When I click the hold button the following code will be executed.

if ( $action == 'hold' ) {
 $url = "holding_twiml.php";
 $call = $client->calls->read(
        array("ParentCallSid" => $_POST['callSid'])
    )[0];
} else {  // unhold
 $call = $client->calls($_POST['callSid'])->fetch();
 $url = "redirecting_twiml.php";
}
$call->update(
    array(
        "url" => $url,
        "method" => "POST"
    )
);

holding_twiml.php

<Response>
    <Enqueue waitUrl="hold_music_twiml.xml">xx</Enqueue>
</Response>

hold_music_twiml.xml

<Response>
    <Play>http://demo.twilio.com/docs/classic.mp3</Play>
</Response>

redirecting_twiml.php

<Response>
  <Dial action="hold_twiml.php">
    <Queue>xx</Queue>
  </Dial>
</Response>

Now on clicking Hold, the call on browser is getting ended and the call over client(phone) is put into hold.

Can anyone help me to fix the issue? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doufeixuan8882 2017-07-06 15:46
    关注

    Twilio developer evangelist here.

    You are using an action attribute on the <Dial> TwiML. From the documentation:

    If you provide an 'action' URL, Twilio will continue the current call after the dialed party has hung up, using the TwiML received in your response to the 'action' URL request.

    So, when the client hangs up, Twilio is continuing the call using the TwiML received from your action URL.

    If you remove the action attribute or change the TwiML to <Hangup/> then your call will end when the client hangs up.

    Let me know if that helps at all.

    评论

报告相同问题?