Skip to content

Instantly share code, notes, and snippets.

@TMcManus
Last active August 29, 2015 13:57
Show Gist options
  • Save TMcManus/9454814 to your computer and use it in GitHub Desktop.
Save TMcManus/9454814 to your computer and use it in GitHub Desktop.
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
// This is the URL which the customer will be redirected to by th POST request to the Call Sid
?>
<Response>
<Say>Thank you for holding. We are now connecting you to an agent.</Say>
<Dial>
<Number url="play-for-agent.xml">
<?php echo $_GET['agent_phone_number'];?>
</Number>
</Dial>
</Response>
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
// The caller will hear ringing until this TwiML completes, so keep this short.
?>
<Response>
<Say>Incoming customer call.</Say>
</Response>
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}.json \
-d "Url=http://example.com/call-agent.php?agent_phone_number=%2b81345678901" \
-d "Method=GET" \
-u '{AccountSid}:{AuthToken}'
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
// The caller will loop through this TwiML until the agent makes a POST request to thier Call Sid
if (!isset($_GET['repeat'])){
// Do something to persist the Call SID and the fact that the call is waiting
}
?>
<Response>
<Say>We'll be with you shortly. Thank you for waiting.</Say>
<Play>hold-music-1.mp3</Play>
<Play>hold-music-2.mp3</Play>
<Play>hold-music-3.mp3</Play>
<Redirect method="GET">waiting.xml?repeat=true</Redirect>
</Response>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment