Instantly share code, notes, and snippets.

What would you like to do?
"result": {
"actions": {
"attempts": 1,
"confidence": 51,
"disposition": "SUCCESS",
"interpretation": "7148745213",
"name": "phone",
"utterance": "Hugh Jazz",
"value": "7148745213",
"xml": "<?xml version=\"1.0\"?>\r\n<result grammar=\"0@a2a3e03d.vxmlgrammar\">\r\n <interpretation grammar=\"0@a2a3e03d.vxmlgrammar\" confidence=\"51\">\r\n \r\n <input mode=\"speech\">Hugh Jazz<\/input>\r\n <\/interpretation>\r\n<\/result>\r\n"
"callId": "7a6c80d2197102e1691bc7f8d12b0a66",
"complete": true,
"error": null,
"sequence": 1,
"sessionDuration": 11,
"sessionId": "02a252f059fc07155158102e794bde60",
"state": "ANSWERED"
// Inlcude the PHPGrammar class file.
// An array to hold names and phone numbers of employees (you could easily get this from any data source).
$employees = Array();
$employees[0] = Array("fname" => "Amanda", "lname" => "Hugankiss", "phone" => "7148596547");
$employees[1] = Array("fname" => "Hugh", "lname" => "Jazz", "phone" => "7148745213");
$employees[2] = Array("fname" => "Joe", "lname" => "Schmo", "phone" => "7845987456");
$employees[3] = Array("fname" => "John", "lname" => "Public", "phone" => "4785412364");
// Create a new grammar instance.
$grammar = new Grammar(false, "en-US", "voice", "menu");
// Create a rule for the grammar.
$grammar->startRule("menu", GrammarScope::$public);
// Iterate over the employees array.
for($i=0; $i<count($employees); $i++) {
$grammar->item($employees[$i]["fname"], "0-1");
$grammar->endElement(); // End element for one-of.
$grammar->endElement(); // End element for rule.
// Write the grammar out for applications to consume.
// Include the Tropo PHP WebAPI library.
// Include the Limonade Framework.
// 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" =>
"next" => "$scriptURL?uri=transfer",
"say" => "Transferring. Please hold..."));
// Write out the JSON for Tropo to consume.
// 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();
// Write out the JSON for Tropo to consume.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment