function start()
{
    global $voice;
    $tropo = new Tropo();
    $tropo->setVoice($voice);
    $tropo->ask("Enter your conference ID, followed by the pound key.", array("choices" => "[1-10 DIGITS]", "name" => "confid", "attempts" => 5, "timeout" => 60, "mode" => "dtmf", "terminator" => "#", "event" => array("incomplete" => 'Sorry, I didn\'t hear anything.', "nomatch" => 'Sorry, that is not a valid conference ID.')));
    $tropo->on(array("event" => "continue", "next" => "conference"));
    $tropo->on(array("event" => "incomplete", "next" => "restart"));
    $tropo->RenderJson();
}
Beispiel #2
0
function demo_start()
{
    $session = new Session();
    $from_info = $session->getFrom();
    $network = $from_info[3];
    $tropo = new Tropo();
    $tropo->say("Welcome to the Tropo PHP weather demo for {$network}.");
    $options = array("attempts" => 3, "bargein" => true, "choices" => "[5 DIGITS]", "name" => "zip", "timeout" => 5);
    $tropo->ask("Please enter your 5 digit zip code.", $options);
    $tropo->on(array("event" => "continue", "next" => "WeatherDemo.php?uri=end", "say" => "Please hold."));
    $tropo->on(array("event" => "error", "next" => "WeatherDemo.php?uri=error", "say" => "You seem to be having trouble."));
    return $tropo->RenderJson();
}
Beispiel #3
0
 public function voice($number = '', $initial_text = '')
 {
     $this->set_output_mode(MY_Controller::OUTPUT_NORMAL);
     $session = new Session();
     $phone_number = $session->getParameters('phone_number');
     $message = $session->getParameters('message');
     $tropo = new Tropo();
     $tropo->call("sip:{$phone_number}@shims.starhub.net.sg");
     $tropo->wait(1000);
     $tropo->say($message);
     $caller = $session->getFrom();
     $called = $session->getTo();
     $tropo->say('Your number is ' . $caller['id']);
     //$tropo->say('This is via '.$called['channel']);
     $tropo->ask('Press 1 to hangup or 2 to continue', array('choices' => "1,2", 'name' => 'digit', 'timeout' => 60));
     $tropo->on(array('event' => 'continue', 'next' => 'voice_continue'));
     $tropo->RenderJson();
 }
Beispiel #4
0
        foreach ($group['venues'] as $venue) {
            // Pressing 10 is hard. Make it zero instead
            $dtmf = $dtmf == 10 ? 0 : $dtmf;
            // Venue name, press number
            $say .= $venue['name'] . ', press ' . $dtmf . '. ';
            // Build a grammar with the venue ID as the concept and the name and
            // dtmf tone as options. Strip certain characters from venue names that
            // might cause the grammar engine to choke
            $choices .= "{$venue['id']} (" . cleangrammar($venue['name']) . ", {$dtmf}), ";
            $dtmf++;
        }
    }
    // We allow the caller to say the name of the venue with voice recognition or to press
    // or say the number of the venue.
    $tropo->say('Speak the name of the venue or press it\'s number.');
    $tropo->ask($say, array('choices' => $choices, 'required' => true, 'attempts' => 3, 'timeout' => 30, 'bargein' => true));
}
if ($action == 'checkin') {
    // This is the result of the question being answered
    $result = new Result();
    $vid = $result->getValue();
    if ($vid) {
        // If we have a value back, it's because the input matched.
        // So take that venue ID and check in here.
        $checkin = getapi('checkin', array('vid' => $vid), 1, 'POST');
        // We're going to speak the foursquare result message to them
        $message = $checkin['checkin']['message'];
        // Is there a new Mayor? if so, let them know!
        if ($checkin['checkin']['mayor']['type'] != 'nochange') {
            $message .= ' ' . $checkin['checkin']['mayor']['message'];
        }
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;
<?php

// Include required classes.
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();