Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created January 21, 2010 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheadd/283007 to your computer and use it in GitHub Desktop.
Save mheadd/283007 to your computer and use it in GitHub Desktop.
<?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