Nabin  Nembang
Nabin Nembang

Reputation: 753

Twilio: How to play prerecorded voice to recevier's answering machine?

With twilio Api I am trying implement the following:

  1. Agent Clicks number in a list to dial through twilio javaacript web client
  2. If receiver is not available and his answering machine responds back then agent have an option to click button on my website to play prerecorded audio that will be left on his machine

But I am not able to transfer a call to prerecorded audio. What i tried so far is updating in progress call to page which outputs twiml play verb as below:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Play>https://mywebsite.com/audio.mp3</Play>
</Response>

But as soon as call is redirected to above twiml, reciever phone seems to be disconnected and no prerecorded audio is left to his voicemail, instead audio is played back to agent(caller).

I tried updating both parent call and child call(obtained from parentsid and child sid) , But it doesn't seem to work.

My php code for updating call:

$client->calls($callSid)->update([
      'url' => route('twilio.play-vm'),
      'StatusCallback' => route('twillo.call-complete')
 ]);

//Trying with child call
$childCall = $client->calls->read(['parentCallSid' => $callSid])[0];
$childCall->update([
          'record' => true,
          'url' => route('twilio.play-vm'),
          'StatusCallback' => route('twillo.call-complete')
]);  

Upvotes: 0

Views: 836

Answers (1)

Devin Rader
Devin Rader

Reputation: 10366

Twilio developer evangelist here.

Have you thought about using Answering Machine Detection (AMD)?

In your scenario I can see you a couple different ways.

  1. Have the agents button click tell your application to use the REST API to initiate an outbound call to your customer with AMD enabled. If the AMD webhook tells you a human has answered return a <Dial> back to Twilio that tells use to call the agent and connect them to the customer. Otherwise return the <Play> to Twilio.

  2. Have the agents button click tell your application start a call from their app, but when Twilio answers <Dial> the agent into an conference call. At the same time you have your app use the REST API to initiate an outbound call to the customer using AMD. In the AMD webhook, if a human is detected <Dial> that call into the existing conference with the agent. Otherwise <Play> your audio file.

Hope that helps.

Upvotes: 1

Related Questions