public function testUseDifferentOptionsOrder()
 {
     $tropo = new Tropo();
     $options = array('from' => "3055551212", 'network' => "SMS", 'timeout' => 10, 'headers' => array('foo' => 'bar', 'bling' => 'baz'), 'channel' => "TEXT", 'to' => "3055195825", 'answerOnMedia' => false, 'voice' => 'kate');
     $tropo->message("This is an announcement", $options);
     $this->assertEquals($this->expected, sprintf($tropo));
 }
Example #2
0
function demo_error()
{
    $tropo = new Tropo();
    $tropo->say("Please try your request again later.");
    $tropo->hangup();
    return $tropo->renderJSON();
}
function app_continue()
{
    $tropo = new Tropo();
    @($result = new Result());
    $userType = $result->getUserType();
    $tropo->say("You are a {$userType}");
    $tropo->RenderJson();
}
Example #4
0
 public function testCallUsingCallObject()
 {
     $tropo = new Tropo();
     $rec = new StartRecording('recording', 'audio/mp3', 'POST', 'password', 'http://blah.com/recordings/1234.wav', 'jose');
     $call = new Call("3055195825", "3055551212", "SMS", "TEXT", false, 10, array('foo' => 'bar', 'bling' => 'baz'), $rec);
     $tropo->call($call);
     $this->assertEquals('{"tropo":[{"call":{"to":"3055195825","from":"3055551212","network":"SMS","channel":"TEXT","timeout":10,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"recording":{"format":"audio/mp3","method":"POST","password":"******","url":"http://blah.com/recordings/1234.wav","username":"******"}}}]}', sprintf($tropo));
 }
Example #5
0
 public function voice_continue()
 {
     $this->set_output_mode(MY_Controller::OUTPUT_NORMAL);
     $tropo = new Tropo();
     @($result = new Result());
     $answer = $result->getValue();
     $tropo->say("You said " . $answer);
     $tropo->RenderJson();
 }
Example #6
0
 public function testAskWithNullOptions()
 {
     $say = new Say("Please say your account number");
     $choices = new Choices("[5 DIGITS]");
     $options = array('say' => $say, 'choices' => $choices, 'timeout' => NULL);
     $tropo = new Tropo();
     $tropo->Ask($options);
     $this->assertEquals($this->expected, sprintf($tropo));
 }
Example #7
0
 public function testRecordTranscription()
 {
     $say = new Say("Please say your account number");
     $choices = new Choices("[5 DIGITS]", NULL, "#");
     $transcription = new Transcription('http://example.com/', 'bling', 'encoded');
     $tropo = new Tropo();
     $tropo->Record(NULL, NULL, true, $choices, NULL, 5, "POST", NULL, NULL, $say, NULL, NULL, $transcription);
     $this->assertEquals('{"tropo":[{"record":{"beep":true,"choices":{"value":"[5 DIGITS]","termChar":"#"},"maxSilence":5,"method":"POST","say":{"value":"Please say your account number"},"transcription":{"id":"bling","url":"http://example.com/","emailFormat":"encoded"}}}]}', sprintf($tropo));
 }
Example #8
0
 public function testConferenceWithOnHandler()
 {
     $say = new Say('Welcome to the conference. Press the pound key to exit.');
     // Set up an On object to handle the event.
     // Note - statically calling the properties of the Event object can be used
     //   as the first parameter to the On Object constructor.
     $on = new On(Event::$join, NULL, $say);
     $options = array('id' => 1234, 'mute' => 'false', 'terminator' => '#', 'playTones' => false, 'name' => 'foo', 'on' => $on);
     $tropo = new Tropo();
     $tropo->Conference($options);
     $this->assertEquals('{"tropo":[{"conference":{"id":1234,"mute":false,"on":{"event":"join","say":{"value":"Welcome to the conference. Press the pound key to exit."},"name":"foo","playTones":false,"terminator":"#"}}]}', sprintf($tropo));
 }
function conference()
{
    global $voice;
    $tropo = new Tropo();
    $tropo->setVoice($voice);
    $result = new Result();
    $conference = $result->getValue();
    $tropo->say('<speak>Conference ID <say-as interpret-as=\'vxml:digits\'>' . $conference . '</say-as> accepted.</speak>');
    $tropo->say('You will now be placed into the conference. Please announce yourself. To exit the conference without disconnecting, press pound.');
    $tropo->conference($conference, array('id' => $conference, 'terminator' => '#'));
    $tropo->say('You have left the conference.');
    $tropo->on(array("event" => "continue", "next" => "restart"));
    $tropo->RenderJson();
}
<?php

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" => "Kate"));
$tropo->RenderJson();
<?php

/**
 * Updating an application to add Voice / Messaging URLs.
 * This will add both a voice and messaging URL to an existing application; these are the URLs 
 *  that power voice calls and SMS/messaging calls for your application. This can be a file 
 *  hosted at hosting.tropo.com or hosted on an external server, depending on the application.
 */
use Tropo\Exception\TropoException;
require_once '../tropo.class.php';
$userid = "";
$password = "";
$applicationID = "";
$tropo = new Tropo();
try {
    $appSettings = array("name" => "My Awesome App", "voiceUrl" => "http://www.anotherfake.com/index.php", "messagingUrl" => "http://www.anotherfake.com/index2.php", "platform" => "webapi", "partition" => "staging");
    echo $tropo->updateApplicationProperty($userid, $password, $applicationID, $appSettings);
} catch (TropoException $ex) {
    echo $ex->getMessage();
}
<?php

/**
 * Deleting an Application
 * Use the deleteApplication() method to remove an application. This cannot be undone; once an application has been
 * deleted, it cannot be restored without recreating it from scratch.
 * 
 */
require_once '../tropo.class.php';
$userid = "";
$password = "";
$applicationID = "";
$tropo = new Tropo();
try {
    echo $tropo->deleteApplication($userid, $password, $applicationID);
} catch (TropoException $ex) {
    echo $ex->getMessage();
}
function zip_error()
{
    // Step 1. Create a new instance of the Tropo object.
    $tropo = new Tropo();
    // Step 2. This is the last thing the user will be told before the session ends.
    $tropo->say("Please try your request again later.");
    // Step 3. End the session.
    $tropo->hangup();
    // Step 4. Render the JSON for the Tropo WebAPI to consume.
    return $tropo->renderJSON();
}
<?php

/**
 * Creating a New Application
 * Use the createApplication() method to add a brand new application. 
 * You can define a voice and messaging URL in the Request Body, but this 
 * method won't assign any addresses. You'll need to update the
 * application once it's created to add a phone number or IM account.
 * 
 */
require_once '../tropo.class.php';
$userid = "";
$password = "";
$tropo = new Tropo();
try {
    $appSettings = array("name" => "My Awesome App", "voiceUrl" => "http://www.fake.com/index.php", "messagingUrl" => "http://www.fake.com/index2.php", "platform" => "webapi", "partition" => "staging");
    echo $tropo->createApplication($userid, $password, $appSettings);
} catch (TropoException $ex) {
    echo $ex->getMessage();
}
Example #15
0
<?php

/*
 * Copyright (c) 2009 - 2015 Tropo, now part of Cisco
 * Released under the MIT license. See the file LICENSE
 * for the complete license
 */
$fsUser = '******';
$fsPass = '******';
require 'TropoClasses.php';
$voice = 'allison';
// set the base URL for the app
$base = !empty($_SERVER['HTTPS']) ? "https://" : "http://";
$base .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$tropo = new Tropo();
$tropo->voice = 'allison';
// set a default action
$action = isset($_GET['event']) ? $_GET['event'] : '/';
if ($action == '/') {
    // This is a new session, not an event.
    // Set up the event that fires when the next response is sent from Tropo
    $tropo->on(array('event' => 'continue', 'next' => $base . '?event=checkin'));
    $tropo->say('Welcome to the Four Square check in I V R.');
    // Get last FS checkin
    $history = getapi('history', null, 1);
    if (!is_array($history['checkins'])) {
        // Since we have no data, foursquare API must be having issues. Hang up.
        $tropo->say('Could not reach the Four Square API. Try again later.');
        print $tropo;
        die;
    }
<?php

/**
 * Updating an Application to Add a Voice Token
 * The updateApplicationAddress() method can be used to add a voice token to your application; you can add a messaging token just by
 * changing the channel to "messaging" instead of "voice".
 * 
 */
require_once '../tropo.class.php';
$userid = "";
$password = "";
$applicationID = "";
$tropo = new Tropo();
try {
    echo $tropo->updateApplicationAddress($userid, $password, $applicationID, array("type" => AddressType::$token, "channel" => "messaging"));
} catch (TropoException $ex) {
    echo $ex->getMessage();
}
<?php

/**
 * Deleting an Address
 * You can use the deleteApplicationAddress() method remove a phone number, IM account or token from an application.
 * 
 */
use Tropo\Exception\TropoException;
use Tropo\REST\AddressType;
require_once '../tropo.class.php';
$userid = "";
$password = "";
$applicationID = "";
$number = "";
$tropo = new Tropo();
try {
    echo $tropo->deleteApplicationAddress($userid, $password, $applicationID, AddressType::$number, $number);
} catch (TropoException $ex) {
    echo $ex->getMessage();
}
<?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 the library
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
<?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();
Example #21
0
 public function testHangup()
 {
     $tropo = new Tropo();
     $tropo->Hangup();
     $this->assertEquals('{"tropo":[{"hangup":"null"}]}', sprintf($tropo));
 }
<?php

require_once 'tropo.class.php';
// KLogger is a logging class from
// http://codefury.net/projects/klogger/
require_once 'KLogger.php';
$log = new KLogger("log.txt", KLogger::INFO);
// Does the ?record query string exist? If not, this is an incoming call.
if (!array_key_exists('record', $_GET)) {
    $tropo = new Tropo();
    $tropo->record(array('say' => 'Leave your message at the beep.', 'url' => getself() . '?record'));
    print $tropo;
} else {
    // Change this path to match the location on your server where you want
    // the file to be saved.
    $target_path = 'path/to/recording/' . $_FILES['filename']['name'];
    if (move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) {
        $log->LogInfo("{$target_path} [{$_FILES['filename']['size']} bytes] was saved");
    } else {
        $log->LogError("{$target_path} could not be saved.");
    }
}
// Simple function to get the full URL of the current script.
function getself()
{
    $pageURL = 'http';
    $url = $_SERVER["HTTPS"] == "on" ? 'https' : 'http';
    $url .= "://" . $_SERVER["SERVER_NAME"];
    $url .= $_SERVER["SERVER_PORT"] != "80" ? ':' . $_SERVER["SERVER_PORT"] : '';
    $url .= $_SERVER["REQUEST_URI"];
    return $url;
 public function testStartRecordingWithParameters()
 {
     $tropo = new Tropo();
     $tropo->StartRecording('recording', 'audio/mp3', 'POST', 'password', 'http://blah.com/recordings/1234.wav', 'jose');
     $this->assertEquals('{"tropo":[{"recording":{"format":"audio/mp3","method":"POST","password":"******","url":"http://blah.com/recordings/1234.wav","username":"******"}}]}', sprintf($tropo));
 }
Example #24
0
 protected function _send_reply_message()
 {
     $tropo = new Tropo();
     $tropo->call($this->_session->from_phone_number, array('network' => 'SMS'));
     $tropo->say($this->_session->message);
     $tropo->RenderJson();
 }
<?php

/**
 * Updating an Application to Add an AIM Address
 * The updateApplicationAddress() method can be used to add an AIM account to your application.
 * The same method can be used to add YAHOO, MSN, JABBER, GTALK and SKYPE.
 *
 */
use Tropo\Exception\TropoException;
use Tropo\REST\AddressType;
require_once '../tropo.class.php';
$userid = "";
$password = "";
$applicationID = "";
$tropo = new Tropo();
try {
    $params = array("type" => AddressType::$aim, "username" => "AIMUser01", "password" => "secret");
    echo $tropo->updateApplicationAddress($userid, $password, $applicationID, $params);
} catch (TropoException $ex) {
    echo $ex->getMessage();
}
Example #26
0
<?php

include_once 'tropo.class.php';
$token = 'your token here';
$number = 'the number you would like to dial';
$tropo = new Tropo();
try {
    $session = new Session();
    if ($session->getParams("action") == "create") {
        $tropo->call($session->getParams("dial"));
        $tropo->say('This is an outbound call.');
    } else {
        $tropo->say('Thank you for calling us.');
    }
    $tropo->renderJSON();
} catch (Exception $e) {
    if ($e->getCode() == '1') {
        // The session object threw an exception, so this file wasn't
        // loaded as part of a Tropo session. Launch a Tropo session.
        if ($tropo->createSession($token, array('dial' => $number))) {
            print 'Call launched to ' . $number;
        }
    }
}
Example #27
0
<?php

/**
 * A sample application that demonstrates the use of the TropoPHP package.
 * @copyright 2010 Mark J. Headd (http://www.voiceingov.org)
 */
// Include Tropo classes.
require 'tropo.class.php';
$tropo = new Tropo();
$tropo->say("Hello World!");
$tropo->renderJson();
Example #28
0
<?php

/**
 * A sample application that demonstrates the use of the TropoPHP packeage.
 * @copyright 2010 Mark J. Headd (http://www.voiceingov.org)
 */
// Include Tropo classes.
require 'TropoClasses.php';
$tropo = new Tropo();
$tropo->Say("Hello World!");
$tropo->RenderJson();
function app_error()
{
    $tropo = new Tropo();
    $tropo->say("Something has gone wrong, please call back.");
    $tropo->hangup();
    return $tropo->RenderJson();
}
<?php

/**
 * Updating an Application to Add a Number from the Pool
 * the updateApplicationAddress() method can be used to add a number from the pool of available Tropo numbers, 
 * based on a specified prefix.
 * 
 */
require_once '../tropo.class.php';
$userid = "";
$password = "";
$applicationID = "";
$tropo = new Tropo();
try {
    echo $tropo->updateApplicationAddress($userid, $password, $applicationID, array("type" => AddressType::$number, "prefix" => "1407"));
} catch (TropoException $ex) {
    echo $ex->getMessage();
}