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" => "favorite-movie-webapi.php?uri=choice", "say" => "Please hold."));
        $tropo->on(array("event" => "incomplete", "next" => "favorite-movie-webapi.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();
}
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);
} else {
    // This is a phone call
    $tropo->say("Awww. How nice. You cared enough to call.");
}
print $tropo;
Example #4
0
 protected function _load_session($initial_text)
 {
     $tropo_session = new Session();
     $this->_session->from_phone_number = '';
     $this->_session->initial_text = '';
     $this->_session->command = '';
     $this->_session->parameters = FALSE;
     $this->_session->staff_id = 0;
     if ($tropo_session) {
         $this->_session->command = $tropo_session->getParameters('command');
         $this->_session->message = $tropo_session->getParameters('message');
         if ($this->_session->command == 'send-sms') {
             $this->_session->from_phone_number = $tropo_session->getParameters('phone_number');
             return;
         }
         $this->_session->staff_id = $tropo_session->getParameters('staff_id');
         $this->_session->initial_text = $tropo_session->getInitialText();
         $this->_session->from = $tropo_session->getFrom();
         if (isset($this->_session->from['id'])) {
             $this->_session->from_phone_number = preg_replace('/^' . $this->_config['country_code'] . '/', '', $this->_session->from['id']);
         }
         if ($this->_session->from_phone_number) {
             $row = reset($this->CI->phone_session_model->get_rows(array('phone_number' => $this->_session->from_phone_number)));
             if ($row) {
                 $this->_session->staff_id = $row->staff_id;
                 $user_data = unserialize($row->user_data);
                 if (is_object($user_data)) {
                     $this->_session->command = $user_data->command;
                     $this->_session->parameters = $user_data->parameters;
                 }
             } else {
                 $row = reset($this->CI->staff_model->get_rows(array('phone_number' => $this->_session->from_phone_number)));
                 if ($row) {
                     $this->_session->staff_id = $row->id;
                 } else {
                     echo "Cannot find phone number in list: " . $this->_session->from_phone_number;
                 }
             }
         }
     }
     if ($this->_session->staff_id) {
         $this->CI->staff_model->load_by_id($this->_session->staff_id);
         $this->_session->from_phone_number = $this->CI->staff_model->phone_number;
     }
 }