/
TropoMenu.php
65 lines (46 loc) · 1.88 KB
/
TropoMenu.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
<?php
// Include the Tropo PHP WebAPI library.
require('path/to/TropoClasses.php');
// Include the Limonade Framework.
require('path/to/limonade/lib/limonade.php');
// Set up variables holding path to script and external grammar file.
$hostURL = 'http://'.$_SERVER['SERVER_NAME'];
$scriptURL = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
// The starting point for our caller.
dispatch_post('/start', 'menu_start');
function menu_start() {
GLOBAL $hostURL, $scriptURL;
// Create a new instance of the Tropo object.
$tropo = new Tropo();
// A greeting prompt.
$tropo->say("Welcome to the Tropo speech enabled phone menu example.");
// Set up options form menu, including SRGS grammar to use.
$options = array("attempts" => 3,
"bargein" => true,
"choices" => "$hostURL/SampleGrammar.php;type=application/grammar-xml",
"name" => "phone",
"timeout" => 5);
// Ask the caller to say the name of the person they want to be transferred to.
$tropo->ask("Say the name of the person you want to be transferred to.", $options);
// Set up a handler for the continue event, which is delivered when the caller selection successfully matches the grammar.
$tropo->on(array("event" =>
"continue",
"next" => "$scriptURL?uri=transfer",
"say" => "Transferring. Please hold..."));
// Write out the JSON for Tropo to consume.
$tropo->RenderJson();
}
// After the caller makes a selection, transfer the call.
dispatch_post('/transfer', 'transfer_call');
function transfer_call() {
// Create a new instance of the Result object and get the value of the selection the caller made.
$result = new Result();
$phone = $result->getValue();
// Create a new instance of the Tropo object and transfer the call.
$tropo = new Tropo();
$tropo->transfer('+1'.$phone);
// Write out the JSON for Tropo to consume.
$tropo->RenderJson();
}
run();
?>