Home > Back-end >  Twilio Reject Call Send To Voicemail and Email Link or Voicemail File (mp3)
Twilio Reject Call Send To Voicemail and Email Link or Voicemail File (mp3)

Time:12-21

I have a simple call structure folder with PHP and XML on my server. To handle my incoming calls for my business.

I can't seem to get it to forward to voicemail without errors. (SOLVED 12/18/2021 - See Voicemail.php file update below)

My only issue now is I want the voicemail emailed to a mailbox instead of it sitting on Twilio's console only.

Here is how the call gets triggered.

Customer Calls -> Routes to Webhook -> Handle-Incoming-Call.XML

    <?xml version="1.0" encoding="UTF-8"?>
<Response>
    
    <Redirect>handle-extension.php</Redirect>
</Response>

Then Handle-Extension.PHP looks like this

<?php
    header('Content-type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>';

    echo '<Response>';

    
        # @start snippet
        echo '<Say>Thank you for calling, My Business</Say>';
        echo '<Dial record="true" timeout="15" action="voicemail.php">';
        echo '<Number url="screen-caller.xml"> 10000000000</Number>';
        echo '</Dial>';
        # @end snippet
    
    echo '</Response>';
?>

Then Screen-Caller.XML looks like this (This is what me as a business will hear when I pick up)

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Gather action="handle-screen-input.php" numDigits="1">
        <Say>Call for Your Business</Say>
        <Say>To accept the call, press 1.</Say>
        <Say>To reject the call, press 2.</Say>
    </Gather>

</Response>

When I press 1 I get the call, but when I press 2 I want it to go to voicemail.

Here is the Handle-Screen-Input.PHP

<?php
    header('Content-type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8"?>';

    echo '<Response>';

    $user_pushed = (int) $_REQUEST['Digits'];

    if ($user_pushed == 1)
    {
        echo '<Say>Connecting, say hello.</Say>';
    }
    else {
        echo '<Hangup />';
    }

    echo '</Response>';
?>

I created another Webhook that goes to a TwimLets Forwarding Voicemail to Email when if in case it fails.

Here is the voicemail.php code I found in one of the posts here in Stack.

<?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 recordingStatusCallback="/recording-complete.php"></Record>
</Response>

Do I need to add a file name "recording -complete.php" if so what is that structure look like?

The voicemail works, I am just missing the send to email.

Any help would be greatly appreciated. Thank you

CodePudding user response:

I finally figured it out and will answer my own question just incase someone in the future or currently going through the same issue as I am.

on the voicemail.php file, I changed the "record" line to the following

  <Record action="mail.php"></Record>

Then I created a mail.php file to send the recorded voicemail link to the email address of my choice.

Hope to this helps.

  • Related