forked from disruptiveio/TropoVBX
/
twiml.php
77 lines (69 loc) · 1.93 KB
/
twiml.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
include_once('TwimlDial.php');
define('DIAL_COOKIE', 'state-'.AppletInstance::getInstanceId());
$CI =& get_instance();
$CI->load->library('DialList');
$dialer = new TwimlDial();
$dialer->set_state();
// Respond based on state
switch ($dialer->state) {
case 'hangup':
$dialer->hangup();
break;
case 'new':
if ($dialer->dial_whom_user_or_group instanceof VBX_User || $dialer->dial_whom_user_or_group instanceof VBX_Group) {
// create a dial list from the input state
$dial_list = DialList::get($dialer->dial_whom_user_or_group);
$dialed = false;
do {
$to_dial = $dial_list->next();
if ($to_dial instanceof VBX_User) {
$dialed = $dialer->dial($to_dial);
if ($dialed) {
$dialer->state = $dial_list->get_state();
}
}
} while(!$dialed && $to_dial instanceof VBX_User);
if (!$dialed) {
// nobody to call, push directly to voicemail
$dialer->noanswer();
}
}
else {
// we'll create a token DialList so that we can emulate an
// empty state (ie: we're done) and keep the same logic flow
$dial_list = DialList::load(array());
$dialer->state = $dial_list->get_state();
// arbitrary number, simpler handling
$dialer->addNumber($dialer->dial_whom_or_group);
}
break;
case 'recording':
if(isset($_REQUEST['testing'])) {
// ?? what is this?
break;
}
$dialer->add_voice_message();
break;
default:
// rolling through users, populate dial list from state
$dial_list = DialList::load($dialer->state);
// get the next valid user
$dialed = false;
do {
$to_dial = $dial_list->next();
if ($to_dial instanceof VBX_User) {
$dialed = $dialer->dial($to_dial);
if ($dialed) {
$dialer->state = $dial_list->get_state();
}
}
} while(!$dialed && $to_dial instanceof VBX_User);
if (!$dialed) {
// no users left see what next action is, or go to voicemail
$dialer->noanswer();
}
break;
}
$dialer->save_state();
$dialer->Respond();