Twilio Record does not reach action if caller hangs up without pressing a button

180 Views Asked by At

I have been searching for a work around, but I cannot find anything that guarantees action after recording a voicemail. I have to use my server to check call status to end the call and prevent if from going to voicemail after a completed call when using multi-dial. After we record the voicemail I need to SMS a link to the recording for each employee who missed the call. The only way it works is if the caller presses a button before hanging up. I have been trying to use the RecordingStatusCallback as a work around, but I can't figure out how to ensure that the SMS sends if a recording is received.

    <?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>
        <Record
            action="https://handler.twilio.com/twiml/responsefromserver"
            transcribe="true"
            maxLenth="20"
            RecordingStatusCallbackEvent="Completed"
            RecordingStatusCallback="https://handler.twilio.com/twiml/XXXX"
            transcribeCallback="http://twimlets.com/[email protected]"/>
       </Response>
     <?php
     }
     ?>

Response from Server:

   <?xml version="1.0" encoding="UTF-8"?>
   <Response>
     <Say> Thankyou for leaving a message </Say>
   <Sms to="1XXXXXXX"> John
       You missed a call from {{From}} voice Recording: {{RecordingUrl}}.
    </Sms>
    <Sms to="1XXXXXX"> Joe
        You missed a call from {{From}} voice Recording: {{TranscriptionText}}.
    </Sms>  
    </Response>
2

There are 2 best solutions below

0
Alan On

The recordingStatusCallback can trigger a Twilio Function that can send the SMS’ to the respective parties.

Send Multiple SMS

2
philnash On

First up, the <Sms> TwiML verb is very deprecated. I do not recommend you use it.

Instead, I would recommend you trigger the messages that you want to send by using the REST API's messaging resource when you receive the recording status callback, rather than trying to do as part of the call in TwiML. The recording status callback is an asynchronous webhook that will not affect the call if you respond with TwiML. Any actions you want to take in a recording status callback webhook should be with the REST API.