function app_start() { // Create a new instance of the Session object, and get the channel information. $session = new Session(); $from_info = $session->getFrom(); $network = $from_info['channel']; // Create a new instance of the Tropo object. $tropo = new Tropo(); // See if any text was sent with session start. $initial_text = $session->getInitialText(); // If the initial text is a zip code, skip the input collection and go right to results. if (strlen($initial_text) == 1 && is_numeric($initial_text)) { valid_text($tropo, $initial_text); } else { // Welcome prompt. $tropo->say("Welcome to the Tropo PHP example for {$network}"); // Set up options for input. $options = array("attempts" => 3, "bargein" => true, "choices" => "1,2,3,4", "mode" => "dtmf", "name" => "movie", "timeout" => 30); // Ask the caller for input, pass in options. $tropo->ask("Which of these trilogies do you like the best? Press 1 to vote for Lord of the Rings, press 2 for the original Star Wars, 3 for the Star Wars prequels, or press 4 for the Matrix", $options); // Tell Tropo what to do when the user has entered input, or if there's a problem. This redirects to the instructions under dispatch_post('/choice', 'app_choice') or dispatch_post('/incomplete', 'app_incomplete'). $tropo->on(array("event" => "continue", "next" => "testapp.php?uri=choice", "say" => "Please hold.")); $tropo->on(array("event" => "incomplete", "next" => "testapp.php?uri=incomplete")); } // Render the JSON for the Tropo WebAPI to consume. return $tropo->RenderJson(); }
function zip_start() { // Create a new instance of the Session object, and get the channel information. $session = new Session(); $from_info = $session->getFrom(); $channel = $from_info['channel']; // Create a new instance of the Tropo object. $tropo = new Tropo(); // See if any text was sent with session start. $initial_text = $session->getInitialText(); // If the initial text is a zip code, skip the input collection and get weather information. if (strlen($initial_text) == 5 && is_numeric($initial_text)) { formatWeatherResponse($tropo, $initial_text); } else { // Welcome prompt (for phone channel, and IM/SMS sessions with invalid initial text). $tropo->say("Welcome to the Tropo PHP zip code example for {$channel}"); // Set up options form zip code input $options = array("attempts" => 3, "bargein" => true, "choices" => "[5 DIGITS]", "name" => "zip", "timeout" => 5); // Ask the user for input, pass in options. $tropo->ask("Please enter your 5 digit zip code.", $options); // Tell Tropo what to do when the user has entered input, or if there is an error. $tropo->on(array("event" => "continue", "next" => "get_zip_code.php?uri=end", "say" => "Please hold.")); $tropo->on(array("event" => "error", "next" => "get_zip_code.php?uri=error", "say" => "An error has occured.")); } // Render the JSON for the Tropo WebAPI to consume. return $tropo->RenderJson(); }
<?php //this example accepts parameters passed to it from an outside REST request (such as a curl app) - //it extracts the values of the passed parameters and uses it to send, in this case, an outbound text use Tropo\Action\Session; require 'tropo.class.php'; //brings in the Tropo library $session = new Session(); $to = "+" . $session->getParameters("numbertodial"); $name = $session->getParameters("customername"); $msg = $session->getParameters("msg"); //extracts the contents of the passed parameters and assigns them as variables for later use $tropo = new Tropo(); $tropo->call($to, array('network' => 'SMS')); $tropo->say("OMG " . $name . ", " . $msg . "!"); //actually creates the call, passed the "to" value and then adds in the other variables for the message return $tropo->RenderJson(); //defines the response to Tropo in JSON ?>
<?php // Include required classes. use Tropo\Action\Session; require 'classes/tropo.class.php'; require 'classes/sag/sag.php'; // Grab the raw JSON sent from Tropo. $json = file_get_contents("php://input"); // Create a new Session object and obtain the session ID value. $session = new Session($json); $session_id = $session->getId(); // Insert the Session object into a CouchDB database called sessions. try { $sag = new Sag(); $sag->setDatabase("sessions"); $sag->put($session_id, $json); } catch (SagCouchException $ex) { die("*** " . $ex->getMessage() . " ***"); } // Create a new Tropo object. $tropo = new Tropo(); // Set options for an Ask. $options = array("attempts" => 20, "bargein" => true, "choices" => "[5 DIGITS]", "name" => "zip", "timeout" => 5, "allowSignals" => array("tooLong", "farTooLong")); $tropo->ask("Please enter your 5 digit zip code.", $options); // Set event handlers $tropo->on(array("event" => "continue", "next" => "get_zip_code.php?uri=end", "say" => "Please hold.")); $tropo->on(array("event" => "tooLong", "next" => "get_zip_code.php?uri=end&tooLong=true", "say" => "Please hold on.")); $tropo->on(array("event" => "farTooLong", "next" => "get_zip_code.php?uri=end&farTooLong=true", "say" => "Please hold on for dear life.")); // Render JSON for Tropo to consume. $tropo->renderJSON();
<?php // Include the library use Tropo\Action\Session; use Tropo\Exception\TropoException; require 'tropo.class.php'; try { // If there is not a session object in the POST body, // then this isn't a new session. Tropo will throw // an exception, so check for that. $session = new Session(); } catch (TropoException $e) { // This is a normal case, so we don't really need to // do anything if we catch this. } $caller = $session->getFrom(); $tropo = new Tropo(); // $caller now has a hash containing the keys: id, name, channel, and network $tropo->say("Your phone number is " . $caller['id']); $called = $session->getTo(); // $called now has a hash containing the keys: id, name, channel, and network $tropo->say("You called " . $called['id'] . " but you probably already knew that."); if ($called['channel'] == "TEXT") { // This is a text message $tropo->say("You contacted me via text."); // The first text of the session is going to be queued and applied to the first // ask statement you include... $tropo->ask("This will catch the first text", array('choices' => '[ANY]')); // ... or, you can grab that first text like this straight from the session. $messsage = $session->getInitialText(); $tropo->say("You said " . $message);
<?php use Tropo\Action\Session; require 'tropo.class.php'; error_reporting(0); $tropo = new Tropo(); $session = new Session(); $from = $session->getFrom(); $callerID = $from["id"]; $tropo->say("You are about to enter the conference"); $tropo->conference(null, array("id" => "1234", "name" => "joinleave", "joinPrompt" => "{$callerID} has entered the conference", "leavePrompt" => "{$callerID} has left the conference", "voice" => "Victor")); $tropo->RenderJson();