== connect_company.php // after customer click call me it goes here ==
<?php
require 'twilio.php';
$ApiVersion = "2008-08-01";
$AccountSid = "AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
// Database gets a list of phone numbers to call
$phone_numbers =
array('XXXXXXXXXX',
'XXXXXXXXXX',
'XXXXXXXXXX');
$customer_number =$_REQUEST['customer_number'];
$client = new TwilioRestClient($AccountSid, $AuthToken);
/* make Twilio REST request to initiate outgoing call */
$response = $client->request("/$ApiVersion/Accounts/$AccountSid/Calls",
"Caller" => $phone_numbers[0],
"Called" => $outgoing,
"Url" =>
$url .
"start_call.php?customer_number={$customer_number}&company_numbers=".
implode(',',
$phone_numbers).
'¤t_order=0' ));
?>
== start_call.php // initializes TwiML. This also tracks the current number we are calling. ==
<?php
$phone_numbers =
explode(',',
$_REQUEST['phone_numbers']);
// Adds spaces between numbers for voice
$voice_phone =
implode(' ', str_split
($_REQUEST['customer_number']));
?>
<Response>
<!-- Gather is used to screen voicemail here -->
<Gather action="connect_customer.php?customer_number=<?php echo $_REQUEST['customer_number'] ?>">
<Say>Press
1 to accept a call from a customer with phone number
<?php echo $voice_phone ?>.</Say>
</Gather>
<!-- Make sure no out of bounds in
array error -->
<?php if($_REQUEST['current_order'] +
1 <
count($phone_numbers)):
?> <!-- Redirect if no answer // Remember to escape your & as & in XML -->
<Redirect url="start_call.php?customer_number=<?php echo $_REQUEST['customer_number'] ?>&company_numbers=<?php echo $_REQUEST['company_numbers'] ?>&current_order=".($_REQUEST['current_order'] + 1) />
<!-- No more numbers available. Could redirect here to call company voicemail. -->
<?php else: ?>
<Say>Sorry, no one available to answer your call. We will get back to you shortly.</Say>
<?php endif; ?>
</Response>