3

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

kronus
  • 902
  • 2
  • 16
  • 34

1 Answers1

0

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.

miknik
  • 5,748
  • 1
  • 10
  • 26
  • How do I terminate the first call? Can you share an example? Thanks in advance – kronus Oct 05 '17 at 17:41
  • Have you read the instructions? It's all in there... https://www.twilio.com/docs/api/voice/modify-live-calls#code-terminate-a-running-call – miknik Oct 05 '17 at 17:51
  • Thank you for the link, I tried both "canceled" and "completed" which terminated the call, but I wasn't able to make it call a second time - try {$call = $client->calls("CA9fa06d049c89efb3dc6a2b907f212754")->update(array("status" => "canceled"));echo $call->direction. " call id: " . $call->sid; - when I try with a status of ringing or queued, the response is invalid status – kronus Oct 06 '17 at 15:05