Drop the first call and dial again using Twilio PHP for ringless voicemail

1.2k Views Asked by At

I read the following Twilio PHP API docs and it was successful

I continued reading about ringless voice mail stackoverflow and that it is based on calling a number, then immediately calling the number from the same number again, followed by dropping the initial call, which sends the second call straight to voice mail

How can I do that within the following try catch:

try {
    // Initiate a new outbound call
    $call = $client->account->calls->create(
        // Step 4: Change the 'To' number below to whatever number you'd like 
        // to call.
        "+15558675309",

        // Step 5: Change the 'From' number below to be a valid Twilio number 
        // that you've purchased or verified with Twilio.
        "+15017250604",

        // Step 6: Set the URL Twilio will request when the call is answered.
        array("url" => "http://demo.twilio.com/welcome/voice/")
    );
    echo "Started call: " . $call->sid;
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

I have tried to throw an exception - throw new Exception('something');

I have tried adding goto secondCall; after the $call->sid; followed by secondCall: with the try catch once again

1

There are 1 best solutions below

3
On

I'm not confident that this would always work, and you run the obvious risk of one of the calls connecting and then immediately hanging up, which would be annoying for whoever you are calling.

Anyway, this would be my approach.

Initiate first call and specify a StatusCallbackEvent to fire when the call is initiated (optionally you might want another to fire on ringing). Have this POST to your second call handling script on your server.

Configure that script to terminate the first call and initiate the second call once it receives the callback to say the first call has been initiated, or when the first call is ringing if you don't care about annoying whoever you are trying to call.

You'll probably have to experiment with a timeout if you go with the initiated callback as call setup times can vary a lot, but I don't know how networks decide when to route to voicemail so you might not.