Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created April 1, 2010 00:46
Show Gist options
  • Save mheadd/351155 to your computer and use it in GitHub Desktop.
Save mheadd/351155 to your computer and use it in GitHub Desktop.
<?php
// Include Limonade PHP Framework (http://www.limonade-php.net/).
require('path/to/limonade/lib/limonade.php');
// Include Tropo classes (http://github.com/mheadd/TropoPHP).
require('path/to/TropoClasses.php');
dispatch_post('/start', 'tropo_start');
function tropo_start() {
// Get the JSON data submitted from the Tropo Web API
$session_json = file_get_contents("php://input");
// Create a new Tropo Session Object and determine the channel in use.
$session = new Session($session_json);
$to = $session->getTo();
$channel = $to[3];
// Set the greeting prompt according to the channel.
if($channel == 'PSTN') {
$greetingText = "Welcome to my Phone application. ";
}
else {
$greetingText = "Welcome to my SMS application. ";
}
// Create a new instance of the Tropo Object and add the greeting text.
// Note - using simple Say() method invocation.
$tropo = new Tropo();
$tropo->Say($greetingText);
// Ask the user to enter their zip code.
// Note - using complex Say() method invocation.
$say = new Say("Please enter your five digit zip code.");
$choices = new Choices("[5 DIGITS]");
$ask = new Ask(NULL, true, $choices, NULL, "foo", true, $say, 30);
$tropo->Ask($ask);
// Add an event handler.
$next = str_replace("start", "end", 'http://'.$_SERVER['SERVER_ADDR'].$_SERVER['PHP_SELF']."?tropo-engine=json");
$on = new On(Event::$continue, $next);
$tropo->On($on);
// Render the JSON for Tropo.
return $tropo->renderJSON();
}
dispatch_post('/end', 'tropo_end');
function tropo_end() {
// Get the JSON data submitted from the Tropo Web API
$result_json = file_get_contents("php://input");
// Create a new instance of the Result Object and determine the user input.
$result = new Result($result_json);
$utterance = $result->getUtterance();
// Read back the user input and get out of Dodge...
$tropo = new Tropo();
$tropo->Say("You entered, ".$utterance ." Goodbye");
$tropo->Hangup();
// Render the JSON for Tropo.
return $tropo->renderJSON();
}
run();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment