Created
January 21, 2010 18:06
-
-
Save mheadd/283005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* PHP Classes for interacting with the Voxeo Tropo Web API. | |
* Copyright 2009 Mark J. Headd. | |
* www.voiceingov.org | |
*/ | |
/* | |
* Class for interacting with the Tropo Web API. | |
*/ | |
class Tropo_API { | |
public $_session; | |
public $_result; | |
// Gets the session JSON returned from Tropo. | |
public function sessionSet($session) { | |
$this->_session = json_decode($session); | |
} | |
// Gets the result JSON returned from tropo | |
public function resultSet($result) { | |
$this->_result = json_decode($result); | |
} | |
// Render JSON response to Tropo Web API. | |
public function renderTropoResponse($tropo) { | |
header("Content type: application/json"); | |
echo json_encode($tropo); | |
} | |
} | |
/* | |
* The root element for the JSON payload sent to the Tropo Web API. | |
*/ | |
class Tropo { | |
public $tropo = array(); | |
public function __construct() { } | |
public function __set($name, $value) { | |
array_push($this->tropo, array($name => $value)); | |
} | |
} | |
/* | |
* Sends a prompt to the user and optionally waits for a response. | |
*/ | |
class Ask { | |
public $attempts = 1; | |
public $bargein = true; | |
public $choiceConfidence = 0.3; | |
public $minConfidence = 0.5; | |
public $name = ""; | |
public $required = true; | |
public $timeout = 5.0; | |
public $on; | |
public $choices; | |
public $say; | |
public function __construct() { } | |
public function setOn(On $on) { | |
$this->on = $on; | |
} | |
public function setChoices(Choices $choices) { | |
$this->choices = $choices; | |
} | |
public function setSay(Say $say) { | |
$this->say = $say; | |
} | |
} | |
/* | |
* Defines a simple grammar that will be active for the prompting of the user for input. | |
*/ | |
class Choices { | |
public $value; | |
public $mode; | |
public function __construct($value, $mode) { | |
$this->value = $value; | |
$this->mode = $mode; | |
} | |
} | |
/* | |
* Allows multiple lines in separate sessions to be conferenced together so that the parties on each line | |
* can talk to each other simultaneously. | |
*/ | |
class Conference { | |
public $id = ""; | |
public $maxTime = 0.3; | |
public $mute = false; | |
public $name = ""; | |
public $playTones = false; | |
public $required = true; | |
public $terminator = ""; | |
public $on; | |
public function __construct() { } | |
public function setOn(On $on) { | |
$this->on = $on; | |
} | |
} | |
/* | |
* Instructs Tropo to "hang-up" or disconnect the session associated with the current session. | |
* | |
*/ | |
class Hangup { | |
public function __construct() { } | |
} | |
/* | |
* Adds an event callback so that an application may be notified when a particular event occurs. | |
* Possible events are: "continue", "error", "incomplete" and "hangup". | |
*/ | |
class On { | |
public $event; | |
public $say; | |
public $next; | |
public function __contruct($event, $say, $next) { | |
$this->event = $event; | |
$this->say = $say; | |
$this->next = $next; | |
} | |
} | |
/* | |
* Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded. | |
*/ | |
class Record { | |
public $beep = false; | |
public $format = ""; | |
public $maxSilence = 5; | |
public $maxTime = 0.3; | |
public $password = ""; | |
public $username = ""; | |
public $on; | |
public $choices; | |
public function __construct() { } | |
public function setOn(On $on) { | |
$this->on = $on; | |
} | |
public function setChoices(Choices $choices) { | |
$this->choices = $choices; | |
} | |
} | |
/* | |
* Forwards an incoming call to another destination / phone number before answering it. | |
*/ | |
class Redirect { | |
public $from; | |
public $to; | |
public function __construct() { } | |
} | |
/* | |
* Allows Tropo applications to reject incoming sessions before they are answered. | |
*/ | |
class Reject { | |
public $reject = NULL; | |
public function __construct() { } | |
} | |
/* | |
* When the current session is a voice channel this key will either play a message or an audio file from a URL. | |
* In the case of an text channel it will send the text back to the user via i nstant messaging or SMS. | |
* | |
*/ | |
class Say { | |
public $value; | |
public function __construct($value) { | |
$this->value = $value; | |
} | |
} | |
/* | |
* Allows Tropo applications to begin recording the current session. | |
* The resulting recording may then be sent via FTP or an HTTP POST/Multipart Form. | |
* | |
*/ | |
class startRecording { | |
public $name = ""; | |
public $url = ""; | |
public function __construct() { } | |
} | |
/* | |
* Stops the recording of a current session. | |
*/ | |
class stopRecording { | |
public function __construct() { } | |
} | |
/* | |
* Transfers an already answered call to another destination / phone number. | |
*/ | |
class transfer { | |
public $to; | |
public function __construct() { } | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment