How to Receive and Send voicemail from/on Twilio number?

岁酱吖の 提交于 2021-01-29 14:57:04

问题


I am creating a Twilio based application that will receive the Voicemail if the call is not picked up.

For now, I had set up the incoming call URL in the console against the phone number.

<?php
    header('content-type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";        
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    file_put_contents('incoming_call.log', "\n" .json_encode($_REQUEST) . "\n", FILE_APPEND);
?>

<Response>
    <Dial timeout="15" action="/voicemail.php">          
    </Dial>
</Response>

Whereas my voicemail.php file will has to code

<?php
// echo "hello ";exit;
    header('content-type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

    file_put_contents('incoming_voicemail.log', "\n" .json_encode($_REQUEST) . "\n", FILE_APPEND);
?>
<Response>
  <Say voice="alice">Your call could not be answered at the moment. Please leave a voice message. 
  </Say>
  <Record></Record>
</Response>

I am not receiving the voicemail. Where can I setup the recordingStatusCallback attribute in twiml?

Secondly, I am trying to send voicemail from Twilio number to phone number by dialing One calling and again dial a Second call as the second call will receive a busy status and we are able to send a voicemail, but it's not working. My code is

$call = $twilio->account->calls->create(                
    $phone_no, // To
    $from_no, // From
    array(
        "method" => "GET",
         "statusCallback" => SURL . "voicemail?to_phone_no=" . $phone_no,
          "statusCallbackEvent" => ["initiated","ringing"],
          "statusCallbackMethod" => "POST",
          "twiml" => '<Response><Say>Testing voicemail</Say></Response>'
      )
    );
    sleep(3);
    $call2 = $twilio->account->calls->create(
        $phone_no, // To
        $from_no, // From
        array(
            "url" => AURL.'Vm/audio_file'
        )
    );

Please guide me what I am doing wrong. For help thanks in advance.


回答1:


Twilio developer evangelist here.

For your first question, if you don't include a number (or a SIP address, or a Client identity) to try to connect to, then the <Dial> will move straight on to the action URL, without bothering with the timeout.

If you want the <Dial> to try to connect to a phone, then you should add a phone number.

Second, if you want to receive a webhook when the recording is complete, then you need to add the recordingStatusCallback attribute, with a URL to send the webhook to, to your <Record>, e.g.:

<Response>
  <Say voice="alice">Your call could not be answered at the moment. Please leave a voice message. 
  </Say>
  <Record recordingStatusCallback="/recording-complete.php"></Record>
</Response>

Finally, we do not support the final use case of trying to dial a number twice in order to block it up and then leave a voicemail. Making calls and then dropping them is against the terms of service (see point 19 under "prohibited services". So I encourage you to consider a different way to reach out to your customers or contacts that engages with them in a legitimate way.



来源:https://stackoverflow.com/questions/65714735/how-to-receive-and-send-voicemail-from-on-twilio-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!