-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject-gather.php
48 lines (41 loc) · 1.31 KB
/
inject-gather.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once('include.php');
$client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Get the call SIDs of each caller
$response = $client->request('/'.API_VERSION.'/Accounts/'.ACCOUNT_SID.'/Calls', 'GET', array(
'Status' => 'in-progress'
));
if ($response->IsError) {
echo 'Error: '.$response->ErrorMessage;
}
else {
foreach ($response->ResponseXml->Calls->Call as $call)
{
if ($call->To == AGENT)
{
$agent = $call->Sid;
}
else if ($call->To == FROM_NUMBER)
{
$lead = $call->Sid;
}
}
}
if ( (strlen($agent) == 34) && (strlen($lead) == 34) )
{
echo 'Injecting <Gather><br>';
// Place the lead on hold
$response = $client->request('/'.API_VERSION.'/Accounts/'.ACCOUNT_SID.'/Calls/'.$lead, 'POST', array(
'Url' => BASE_URL.'hold.xml'
));
// The lead has been put in the conference room, get their new call SID.
$lead = $response->ResponseXml->Call->Sid;
// Inject a gather for the agent
$response = $client->request('/'.API_VERSION.'/Accounts/'.ACCOUNT_SID.'/Calls/'.$agent, 'POST', array(
'Url' => BASE_URL.'gather.php?agent='.$agent.'&lead='.$lead
));
}
else {
echo 'Could not get call SIDs for the calls. Please ensure that the call is active and that both agent and lead can hear each other. If so, please refresh the page to try again.';
}
?>