KarmoP
KarmoP

Reputation: 3

Twilio outgoing call to recipient with call screening (Google voice)

I have a working service, where we do outgoing calls something like this.

$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$call = $twilio->calls
               ->create("+14155551212", // to
                        "+14155551212", // from
                        ["url" => "http://demo.twilio.com/docs/classic.mp3"]
               );

print($call->sid);

The issue is when the recipient has call screening, the callback to the URL parameter is done as soon as the screening starts (with callbackstatus "in-progress"!), which means we have to add a pause in the response.

<Response>
    <Pause length="10"/>
    <Say>
This is an important message
</Say>
    <Gather action="https://xxx" method="GET" timeout="15" speechTimeout="auto" numDigits="1" input="dtmf speech">
        <Say>Please press 1 followed by the pound sign or say confirm to confirm your appointment</Say>
    </Gather>
    <Redirect method="GET">https://xxx</Redirect>
</Response>

Is there some way to bypass the screening or have the system not start the response in screening?

EDIT: I've added the AMD options and it seems to be correctly somewhat working. Right now the only issue that remains is when calling in to Google Voice, when there's call screening, my added voice recording start reading before the recipient actually answers

$call = $client->calls->create(
          $to, $from,
          array(
            "url" => $url,
            "statusCallback" => $statusURL,
            "statusCallbackMethod" => 'POST',
            "machineDetection" => "DetectMessageEnd",
            "machineDetectionTimeout" => 5
          )
        );

Upvotes: 0

Views: 110

Answers (1)

philnash
philnash

Reputation: 73075

You are looking for answering machine detection (AMD).

You can make a call with AMD enabled by setting the MachineDetection parameter to Enable or DetectMessageEnd.

$call = $twilio->calls
               ->create("+14155551212", // to
                        "+14155551212", // from
                        [
                           "url" => "http://demo.twilio.com/docs/classic.mp3",
                           "machineDetection" => "Enabled"
                        ]
               );

When you use the MachineDetection parameter the request to your url will include an AnsweredBy parameter. From the docs:

Use Enable if you would like Twilio to return an AnsweredBy value as soon as it identifies the called party. This is useful if you would like to take a specific action — for example, connect to an agent, play a message) — for a human but hang up on a machine.

If you would like to leave a voicemail on an answering machine, specify DetectMessageEnd. In this case, Twilio will return an AnsweredBy immediately when a human is detected but for an answering machine, AnsweredBy is returned only once the end of the greeting is reached, usually indicated by a beep.

There is also an option for asynchronous AMD. With asynchronous detection your url is called immediately as if a normal call, but once Twilio has performed the detection an asynchronous webhook is made to a different URL and you can use the callback data to decide whether to update the call.

Upvotes: 1

Related Questions