コード例 #1
0
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();
}
コード例 #2
0
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();
}
コード例 #3
0
<?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);
コード例 #4
0
<?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();