PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 18, 2022

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

 November 18, 2022     twilio, twilio-php, twilio-twiml     No comments   

Issue

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.


Solution

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.



Answered By - philnash
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing