Call someone with Twilio then disconnect me and play a message to other person -
i'm trying create button on webpage (on presonal php webserver) should connect me (either call cellphone or via webclient), call number, want have options either hangup call, or disconnect me play mp3 other person , hangup.
i'm not sure how go it. created twiml, how connect existing call? or there different way it?
<?xml version="1.0" encoding="utf-8"?> <response> <play>https://something-something.twil.io/assets/recording1.mp3</play> <hangup/> </response>
thanks in advance.
i think you're trying do. have list of people you're trying call. app call them , connect you. if hear answering machine, want press key hangup , move on next call. after hang up, first outbound call stays online , leaves .mp3 message recipient?
i believe 1 solution creating conference bot.
your app makes outbound call you, bot , recipient , puts conference room called "room-timestamp" timestamp current time. bot twilio number listens gather dtmf. if press 1, play message 1 hang up. because conference, can hangup @ anytime , move on next call. bot loop few times , if no dtmf detected, hang up. made easier using new outbound conference api can pass conference name instead of conference sid :
https://www.twilio.com/docs/api/rest/participant#list-post
edit:
connect 3 numbers conference room :
$uniqueid = time(); $call = $client->account->calls->create($officeline,$twilionum,
array("url" => "http://yourdomain/conference.php?id=$uniqueid"));
$call = $client->account->calls->create($botline,$twilionum,
array("url" => "http://yourdomain/conference.php?id=$uniqueid"));
$call = $client->account->calls->create($customerline,$twilionum,
array("url" => "http://yourdomain/conference.php?id=$uniqueid"));
this connect 3 numbers conference room:
- $officeline (your number),
- $botline (twilio phone # of bot responds dtmf)
- $customerline (the customer you're calling)
conference.php returns conferenceid calls connect to:
header('content-type: text/xml'); $confid = $_request['id']; echo<<<xmlout <?xml version="1.0" encoding="iso-8859-1"?> <response> <dial> <conference statuscallbackevent="leave" statuscallback="killconference.php">$confid</conference> </dial> </response> xmlout;
killconference.php called conference can terminated when there's 1 person left. make sure bot hangs after playing something.
killconference.php
$theconference = $_request['conferencesid']; $participants = $client ->conferences($theconference) ->participants ->read(); if (count($participants) == 1) { $conference = $client ->conferences($theconference) ->fetch(); $conference->update(array( "status" => "completed" )); }
your botline twilio number pointing bot.php responds dtmf:
bot.php
header('content-type: text/xml'); $dtmf = isset($_request["digits"]) ? $_request["digits"] : ""; $playmore = ""; if ($dtmf == "1") { $playmore = "<say>hey wanted leave message </say><hangup/>\n"; } if ($dtmf == "2") { $playmore = "<play>http://www.soundboard.com/mediafiles/22/224470-33a9f640-d998-45a3-b0c1-31c1687c2ae4.mp3</play><hangup/>\n"; } echo<<<xmlout <?xml version="1.0" encoding="iso-8859-1"?> <response> $playmore <gather action="bot.php" numdigits="1" timeout="30"> </gather> <hangup/> </response> xmlout;
the bot stay on line 30 seconds, if no dtmf entered hangs up. press 1 leave customer message, 2 leroy jenkins
Comments
Post a Comment