Created
January 21, 2010 18:07
-
-
Save mheadd/283007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* A simple example the demonstrates the PHP language binding to the Tropo Web API. | |
* This example uses the Limonade PHP micro framework: | |
* http://limonade.sofa-design.net/ | |
* | |
* In order to work, you need to set up your call route in Tropo to match the start | |
* route below, and use the appropriate querystring paramter for the Tropo Web API: | |
* http://ip_address_of_your_server/tropo_test.php?uri=start&tropo-engine=json | |
*/ | |
require('../limonade/lib/limonade.php'); | |
require('Tropo.php'); | |
dispatch_post('/start', 'tropo_start'); | |
function tropo_start() { | |
// Get the JSON data submitted from the Tropo Web API | |
$postdata = file_get_contents("php://input"); | |
// Create a new instance of the Tropo API object | |
$tropo_api = new Tropo_API(); | |
$tropo_api->sessionSet($postdata); | |
// Do something with the session data here... | |
// Create a new instance of the Tropo object. | |
$tropo = new Tropo(); | |
// Create an event handler. | |
$onContinue = new On(); | |
$onContinue->next = "test.php?uri=end"; | |
$onContinue->say = new Say("Please hold..."); | |
$onContinue->event = "continue"; | |
// Set up input collection for the caller. | |
$ask = new Ask(); | |
$ask->bargein = true; | |
$ask->required = true; | |
$ask->timeout = 30; | |
$ask->name = "account_number"; | |
$ask->say = new Say("Please enter your account number."); | |
$ask->choices = new Choices("[5 DIGITS]", "dtmf"); | |
// Set up the root Tropo object and add elements. | |
$tropo->on = $onContinue; | |
$tropo->ask = $ask; | |
//$tropo->say = new Say("Hello World!"); | |
// Render the JSON output for Tropo to consume. | |
return $tropo_api->renderTropoResponse($tropo); | |
} | |
dispatch_post('/end', 'tropo_end'); | |
function tropo_end() { | |
// Get the JSON data submitted from the Tropo Web API | |
$postdata = file_get_contents("php://input"); | |
// Create a new instance of the Tropo API object | |
$tropo_api = new Tropo_API(); | |
$tropo_api->resultSet($postdata); | |
$account_number = $tropo_api->_result->result->actions->utterance; | |
// Create a new instance of the Tropo object. | |
$tropo = new Tropo(); | |
$tropo->say = new Say("You entered $account_number. Thanks for playing. Goodbye."); | |
$tropo->hangup = new Hangup(); | |
// Render the JSON output for Tropo to consume. | |
return $tropo_api->renderTropoResponse($tropo); | |
} | |
run(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment