Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
2077 lines (1906 sloc) 64.71 kB
<?php
/**
* This file contains PHP classes that can be used to interact with the Tropo WebAPI/
* @see https://www.tropo.com/docs/webapi/
*
* @copyright 2010 Mark J. Headd (http://www.voiceingov.org)
* @package TropoPHP
* @author Mark Headd
* @author Adam Kalsey
*/
/**
* The main Tropo WebAPI class.
* The methods on this class can be used to invoke specifc Tropo actions.
* @package TropoPHP
* @see https://www.tropo.com/docs/webapi/tropo.htm
*
*/
include 'tropo-rest.class.php';
class Tropo extends BaseClass {
/**
* The container for JSON actions.
*
* @var array
* @access private
*/
public $tropo;
/**
* The TTS voice to use when rendering content.
*
* @var string
* @access private
*/
private $_voice;
/**
* The language to use when rendering content.
*
* @var string
* @access private
*/
private $_language;
/**
* Class constructor for the Tropo class.
* @access private
*/
public function __construct() {
$this->tropo = array();
}
/**
* Set a default voice for use with all Text To Speech.
*
* Tropo's text to speech engine can pronounce your text with
* a variety of voices in different languages. All elements where
* you can create text to speech (TTS) accept a voice parameter.
* Tropo's default is "Allison" but you can set a default for this
* script here.
*
* @param string $voice
*/
public function setVoice($voice) {
$this->_voice = $voice;
}
/**
* Set a default language to use in speech recognition.
*
* When recognizing spoken input, Tropo allows you to set a language
* to let the platform know which language is being spoken and which
* recognizer to use. The default is en-us (US English), but you can
* set a different default to be used in your application here.
*
* @param string $language
*/
public function setLanguage($language) {
$this->_language = $language;
}
/**
* Sends a prompt to the user and optionally waits for a response.
*
* The ask method allows for collecting input using either speech
* recognition or DTMF (also known as Touch Tone). You can either
* pass in a fully-formed Ask object or a string to use as the
* prompt and an array of parameters.
*
* @param string|Ask $ask
* @param array $params
* @see https://www.tropo.com/docs/webapi/ask.htm
*/
public function ask($ask, Array $params=NULL) {
if(!is_object($ask)) {
$p = array('as','event','voice','attempts', 'bargein', 'minConfidence', 'name', 'required', 'timeout', 'allowSignals', 'recognizer', 'interdigitTimeout', 'sensitivity', 'speechCompleteTimeout', 'speechIncompleteTimeout');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
if (is_array($event)) {
// If an event was passed in, add the events to the Ask
foreach ($event as $e => $val){
$say[] = new Say($val, $as, $e, $voice);
}
}
$say[] = new Say($ask, $as, null, $voice);
$params["mode"] = isset($params["mode"]) ? $params["mode"] : null;
$params["dtmf"] = isset($params["dtmf"]) ? $params["dtmf"] : null;
$params["terminator"] = isset($params["terminator"]) ? $params["terminator"] : null;
if (!isset($voice) && isset($this->_voice)) {
$voice = $this->_voice;
}
$choices = isset($params["choices"]) ? new Choices($params["choices"], $params["mode"], $params["terminator"]) : null;
$ask = new Ask($attempts, $bargein, $choices, $minConfidence, $name, $required, $say, $timeout, $voice, $allowSignals, $recognizer, $interdigitTimeout, $sensitivity, $speechCompleteTimeout, $speechIncompleteTimeout);
}
$this->ask = sprintf('%s', $ask);
}
/**
* Places a call or sends an an IM, Twitter, or SMS message. To start a call, use the Session API to tell Tropo to launch your code.
*
* @param string|Call $call
* @param array $params
* @see https://www.tropo.com/docs/webapi/call.htm
*/
public function call($call, Array $params=NULL) {
if(!is_object($call)) {
$p = array('to', 'from', 'network', 'channel', 'answerOnMedia', 'timeout', 'headers', 'recording', 'allowSignals', 'machineDetection', 'voice');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$call = new Call($call, $from, $network, $channel, $answerOnMedia, $timeout, $headers, $recording, $allowSignals, $machineDetection, $voice);
}
$this->call = sprintf('%s', $call);
}
/**
* This object allows multiple lines in separate sessions to be conferenced together so that the parties on each line can talk to each other simultaneously.
* This is a voice channel only feature.
*
* @param string|Conference $conference
* @param array $params
* @see https://www.tropo.com/docs/webapi/conference.htm
*/
public function conference($conference, Array $params=NULL) {
if(!is_object($conference)) {
$p = array('name', 'id', 'mute', 'on', 'playTones', 'required', 'terminator', 'allowSignals', 'interdigitTimeout', 'joinPrompt', 'leavePrompt', 'voice');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$id = (empty($id) && !empty($conference)) ? $conference : $id;
$name = (empty($name)) ? (string)$id : $name;
$conference = new Conference($name, $id, $mute, $on, $playTones, $required, $terminator, $allowSignals, $interdigitTimeout, $joinPrompt, $leavePrompt, $voice);
}
$this->conference = sprintf('%s', $conference);
}
/**
* This function instructs Tropo to "hang-up" or disconnect the session associated with the current session.
* @see https://www.tropo.com/docs/webapi/hangup.htm
*/
public function hangup() {
$hangup = new Hangup();
$this->hangup = sprintf('%s', $hangup);
}
/**
* A shortcut method to create a session, say something, and hang up, all in one step. This is particularly useful for sending out a quick SMS or IM.
*
* @param string|Message $message
* @param array $params
* @see https://www.tropo.com/docs/webapi/message.htm
*/
public function message($message, Array $params=null) {
if(!is_object($message)) {
$say = new Say($message);
$to = $params["to"];
$p = array('channel', 'network', 'from', 'voice', 'timeout', 'answerOnMedia','headers');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$message = new Message($say, $to, $channel, $network, $from, $voice, $timeout, $answerOnMedia, $headers);
}
$this->message = sprintf('%s', $message);
}
/**
* Adds an event callback so that your application may be notified when a particular event occurs.
* Possible events are: "continue", "error", "incomplete" and "hangup".
*
* @param array $params
* @see https://www.tropo.com/docs/webapi/on.htm
*/
public function on($on) {
if (!is_object($on) && is_array($on)) {
$params = $on;
if ((array_key_exists('say', $params) && ((array_key_exists('voice', $params) || isset($this->_voice))))){
$v = isset($params["voice"]) ? $params["voice"] : $this->_voice;
$say = new Say($params["say"], null, null, $v);
}else{
$say = (array_key_exists('say', $params)) ? new Say($params["say"]) : null;
}
$next = (array_key_exists('next', $params)) ? $params["next"] : null;
$on = new On($params["event"], $next, $say);
}
$this->on = array(sprintf('%s', $on));
}
/**
* Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded.
* If collected, responses may be in the form of DTMF or speech recognition using a simple grammar format defined below.
* The record funtion is really an alias of the prompt function, but one which forces the record option to true regardless of how it is (or is not) initially set.
* At the conclusion of the recording, the audio file may be automatically sent to an external server via FTP or an HTTP POST/Multipart Form.
* If specified, the audio file may also be transcribed and the text returned to you via an email address or HTTP POST/Multipart Form.
*
* @param array|Record $record
* @see https://www.tropo.com/docs/webapi/record.htm
*/
public function record($record) {
if(!is_object($record) && is_array($record)) {
$params = $record;
$p = array('as', 'voice', 'emailFormat', 'transcription', 'terminator');
foreach ($p as $option) {
$params[$option] = array_key_exists($option, $params) ? $params[$option] : null;
}
$choices = isset($params["choices"])
? new Choices(null, null, $params["choices"])
: null;
$choices = isset($params["terminator"])
? new Choices(null, null, $params["terminator"])
: $choices;
if (!isset($params['voice'])) {
$params['voice'] = $this->_voice;
}
$say = new Say($params["say"], $params["as"], null, null);
if (is_array($params['transcription'])) {
$p = array('url', 'id', 'emailFormat');
foreach ($p as $option) {
$$option = null;
if (!is_array($params["transcription"]) || !array_key_exists($option, $params["transcription"])) {
$params["transcription"][$option] = null;
}
}
$transcription = new Transcription($params["transcription"]["url"],$params["transcription"]["id"],$params["transcription"]["emailFormat"]);
} else {
$transcription = $params["transcription"];
}
$p = array('attempts', 'allowSignals', 'bargein', 'beep', 'format', 'maxTime', 'maxSilence', 'method', 'password', 'required', 'timeout', 'username', 'url', 'voice', 'minConfidence', 'interdigitTimeout');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$record = new Record($attempts, $allowSignals, $bargein, $beep, $choices, $format, $maxSilence, $maxTime, $method, $password, $required, $say, $timeout, $transcription, $username, $url, $voice, $minConfidence, $interdigitTimeout);
}
$this->record = sprintf('%s', $record);
}
/**
* The redirect function forwards an incoming call to another destination / phone number before answering it.
* The redirect function must be called before answer is called; redirect expects that a call be in the ringing or answering state.
* Use transfer when working with active answered calls.
*
* @param string|Redirect $redirect
* @param array $params
* @see https://www.tropo.com/docs/webapi/redirect.htm
*/
public function redirect($redirect, Array $params=NULL) {
if(!is_object($redirect)) {
$to = isset($params["to"]) ? $params["to"]: null;
$from = isset($params["from"]) ? $params["from"] : null;
$redirect = new Redirect($to, $from);
}
$this->redirect = sprintf('%s', $redirect);
}
/**
* Allows Tropo applications to reject incoming sessions before they are answered.
* For example, an application could inspect the callerID variable to determine if the user is known, and then use the reject call accordingly.
*
* @see https://www.tropo.com/docs/webapi/reject.htm
*
*/
public function reject() {
$reject = new Reject();
$this->reject = sprintf('%s', $reject);
}
/**
* 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.
*
* @param string|Say $say
* @param array $params
* @see https://www.tropo.com/docs/webapi/say.htm
*/
public function say($say, Array $params=NULL) {
if(!is_object($say)) {
$p = array('as', 'format', 'event','voice', 'allowSignals');
$value = $say;
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$voice = isset($voice) ? $voice : $this->_voice;
$say = new Say($value, $as, $event, $voice, $allowSignals);
}
$this->say = array(sprintf('%s', $say));
}
/**
* Allows Tropo applications to begin recording the current session.
* The resulting recording may then be sent via FTP or an HTTP POST/Multipart Form.
*
* @param array|StartRecording $startRecording
* @see https://www.tropo.com/docs/webapi/startrecording.htm
*/
public function startRecording($startRecording) {
if(!is_object($startRecording) && is_array($startRecording)) {
$params = $startRecording;
$p = array('format', 'method', 'password', 'url', 'username', 'transcriptionID', 'transcriptionEmailFormat', 'transcriptionOutURI');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$startRecording = new StartRecording($format, $method, $password, $url, $username, $transcriptionID, $transcriptionEmailFormat, $transcriptionOutURI);
}
$this->startRecording = sprintf('%s', $startRecording);
}
/**
* Stops a previously started recording.
*
* @see https://www.tropo.com/docs/webapi/stoprecording.htm
*/
public function stopRecording() {
$stopRecording = new stopRecording();
$this->stopRecording = sprintf('%s', $stopRecording);
}
/**
* Transfers an already answered call to another destination / phone number.
* Call may be transferred to another phone number or SIP address, which is set through the "to" parameter and is in URL format.
*
* @param string|Transfer $transfer
* @param array $params
* @see https://www.tropo.com/docs/webapi/transfer.htm
*/
public function transfer($transfer, Array $params=NULL) {
if(!is_object($transfer)) {
$choices = isset($params["choices"]) ? $params["choices"] : null;
$choices = isset($params["terminator"])
? new Choices(null, null, $params["terminator"])
: $choices;
$to = isset($params["to"]) ? $params["to"] : $transfer;
$p = array('answerOnMedia', 'ringRepeat', 'timeout', 'from', 'allowSignals', 'headers', 'machineDetection', 'voice');
foreach ($p as $option) {
$$option = null;
if (is_array($params) && array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$on = null;
if (array_key_exists('playvalue', $params) && isset($params['playvalue'])) {
$on = new On('ring', null, new Say($params['playvalue']));
} elseif (array_key_exists('on', $params) && isset($params['on'])) {
if (is_object($params['on'])) {
$on = $params['on'];
} else {
if (strtolower($params['on']['event']) == 'ring') {
$on = on(array('ring', null, new Say($params['on']['say']), null, null));
}elseif (strtolower($params['on']['event']) == 'connect') {
$comma = "";
$on = "";
if(isset($params['on']['ring'])){
$on = new On('ring', null, new Say($params['on']['ring']), null, null);
$comma = ",";
}
foreach($params['on']['whisper'] as $key){
foreach($key as $k => $v){
switch($k){
case 'ask':
$on = $on . $comma . new On('connect', null, null, null,$v,null,null,"ask");
break;
case 'say':
$on = $on . $comma . new On('connect', null, $v, null,null,null,null,"say");
break;
case 'wait':
$on = $on . $comma . new On('connect', null, null, null,null,null,$v,"wait");
break;
case 'message':
$on = $on . $comma . new On('connect', null, null, null,null,$v,null,"message");
break;
}
$comma = ",";
}
}
}else{
throw new TropoException("The only event allowed on transfer is 'ring' or 'connect'");
}
}
}
$on = $on == null ? null : sprintf('%s',$on);
$transfer = new Transfer($to, $answerOnMedia, $choices, $from, $ringRepeat, $timeout, $on, $allowSignals, $headers, $machineDetection, $voice);
}
$this->transfer = sprintf('%s', $transfer);
}
/**
* Makes the Tropo sleep an active call in milliseconds
*
* @param Interger $milliseconds
* @param String or Array $allowSignals
* @see https://www.tropo.com/docs/webapi/wait.htm
*/
public function wait($wait) {
if (!is_object($wait) && is_array($wait)){
$params = $wait;
$signal = isset($params['allowSignals']) ? $params['allowSignals'] : null;
$wait = new Wait($params["milliseconds"], $signal);
}
$this->wait = sprintf('%s', $wait);
}
/**
* Launches a new session with the Tropo Session API.
* (Pass through to SessionAPI class.)
*
* @param string $token Your outbound session token from Tropo
* @param array $params An array of key value pairs that will be added as query string parameters
* @return bool True if the session was launched successfully
*/
public function createSession($token, Array $params=NULL) {
try {
$session = new SessionAPI();
$result = $session->createSession($token, $params);
return $result;
}
// If an exception occurs, wrap it in a TropoException and rethrow.
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
public function sendEvent($session_id, $value) {
try {
$event = new EventAPI();
$result = $event->sendEvent($session_id, $value);
return $result;
}
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
/**
* Creates a new Tropo Application
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param array $params
* @return string JSON
*/
public function createApplication($userid, $password, Array $params) {
$p = array('href', 'name', 'voiceUrl', 'messagingUrl', 'platform', 'partition');
foreach ($p as $property) {
$$property = null;
if (is_array($params) && array_key_exists($property, $params)) {
$$property = $params[$property];
}
}
try {
$provision = new ProvisioningAPI($userid, $password);
$result = $provision->createApplication($href, $name, $voiceUrl, $messagingUrl, $platform, $partition);
return $result;
}
// If an exception occurs, wrap it in a TropoException and rethrow.
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
/**
* Add/Update an address (phone number, IM address or token) for an existing Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @param array $params
* @return string JSON
*/
public function updateApplicationAddress($userid, $passwd, $applicationID, Array $params) {
$p = array('type', 'prefix', 'number', 'city', 'state', 'channel', 'username', 'password', 'token');
foreach ($p as $property) {
$$property = null;
if (is_array($params) && array_key_exists($property, $params)) {
$$property = $params[$property];
}
}
try {
$provision = new ProvisioningAPI($userid, $passwd);
$result = $provision->updateApplicationAddress($applicationID, $type, $prefix, $number, $city, $state, $channel, $username, $password, $token);
return $result;
}
// If an exception occurs, wrap it in a TropoException and rethrow.
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
/**
* Update a property (name, URL, platform, etc.) for an existing Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @param array $params
* @return string JSON
*/
public function updateApplicationProperty($userid, $password, $applicationID, Array $params) {
$p = array('href', 'name', 'voiceUrl', 'messagingUrl', 'platform', 'partition');
foreach ($p as $property) {
$$property = null;
if (is_array($params) && array_key_exists($property, $params)) {
$$property = $params[$property];
}
}
try {
$provision = new ProvisioningAPI($userid, $password);
$result = $provision->updateApplicationProperty($applicationID, $href, $name, $voiceUrl, $messagingUrl, $platform, $partition);
return $result;
}
// If an exception occurs, wrap it in a TropoException and rethrow.
catch (Exception $ex) {
throw new TropoException($ex->getMessage(), $ex->getCode());
}
}
/**
* Delete an existing Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @return string JSON
*/
public function deleteApplication($userid, $password, $applicationID) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->deleteApplication($applicationID);
}
/**
* Delete an address for an existing Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @param string $number
* @return string JSON
*/
public function deleteApplicationAddress($userid, $password, $applicationID, $addresstype, $address) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->deleteApplicationAddress($applicationID, $addresstype, $address);
}
/**
* View a list of Tropo applications.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @return string JSON
*/
public function viewApplications($userid, $password) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->viewApplications();
}
/**
* View the details of a specific Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @return string JSON
*/
public function viewSpecificApplication($userid, $password, $applicationID) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->viewSpecificApplication($applicationID);
}
/**
* View the addresses for a specific Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @param string $applicationID
* @return string JSON
*/
public function viewAddresses($userid, $password, $applicationID) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->viewAddresses($applicationID);
}
/**
* View a list of available exchanges for assigning a number to a Tropo application.
* (Pass through to ProvisioningAPI class).
*
* @param string $userid
* @param string $password
* @return string JSON
*/
public function viewExchanges($userid, $password) {
$provision = new ProvisioningAPI($userid, $password);
return $provision->viewExchanges();
}
/**
* Renders the Tropo object as JSON.
*
*/
public function renderJSON() {
header('Content-type: application/json');
echo $this;
}
/**
* Allows undefined methods to be called.
* This method is invloked by Tropo class methods to add action items to the Tropo array.
*
* @param string $name
* @param mixed $value
* @access private
*/
public function __set($name, $value) {
array_push($this->tropo, array($name => $value));
}
/**
* Controls how JSON structure for the Tropo object is rendered.
*
* @return string
* @access private
*/
public function __toString() {
// Remove voice and language so they do not appear in the rednered JSON.
unset($this->_voice);
unset($this->_language);
// Call the unescapeJSON() method in the parent class.
return parent::unescapeJSON(json_encode($this));
}
}
/**
* Base class for Tropo class and indvidual Tropo action classes.
* Derived classes must implement both a constructor and __toString() function.
* @package TropoPHP_Support
* @abstract BaseClass
*/
abstract class BaseClass {
/**
* toString Function
* @abstract __toString()
*/
abstract public function __toString();
/**
* Allows derived classes to set Undeclared properties.
*
* @param mixed $attribute
* @param mixed $value
*/
public function __set($attribute, $value) {
$this->$attribute= $value;
}
/**
* Removes escape characters from a JSON string.
*
* @param string $json
* @return string
*/
public function unescapeJSON($json) {
return str_replace(array('\"', "\"{", "}\"", '\\\\\/', '\\\\'), array('"', "{", "}", '/', '\\'), $json);
}
}
/**
* Base class for empty actions.
* @package TropoPHP_Support
*
*/
class EmptyBaseClass {
final public function __toString() {
return json_encode(null);
}
}
/**
* Action classes. Each specific object represents a specific Tropo action.
*
*/
/**
* Sends a prompt to the user and optionally waits for a response.
* @package TropoPHP_Support
*
*/
class Ask extends BaseClass {
private $_attempts;
private $_bargein;
private $_choices;
private $_minConfidence;
private $_name;
private $_required;
private $_say;
private $_timeout;
private $_voice;
private $_allowSignals;
private $_recognizer;
private $_interdigitTimeout;
private $_sensitivity;
private $_speechCompleteTimeout;
private $_speechIncompleteTimeout;
/**
* Class constructor
*
* @param int $attempts
* @param boolean $bargein
* @param Choices $choices
* @param float $minConfidence
* @param string $name
* @param boolean $required
* @param Say $say
* @param int $timeout
* @param string $voice
* @param string|array $allowSignals
* @param integer $interdigitTimeout
* @param integer $sensitivity
* @param float $speechCompleteTimeout
* @param float $speechIncompleteTimeout
*/
public function __construct($attempts=NULL, $bargein=NULL, Choices $choices=NULL, $minConfidence=NULL, $name=NULL, $required=NULL, $say=NULL, $timeout=NULL, $voice=NULL, $allowSignals=NULL, $recognizer=NULL, $interdigitTimeout=NULL, $sensitivity=NULL, $speechCompleteTimeout=NULL, $speechIncompleteTimeout=NULL) {
$this->_attempts = $attempts;
$this->_bargein = $bargein;
$this->_choices = isset($choices) ? sprintf('%s', $choices) : null ;
$this->_minConfidence = $minConfidence;
$this->_name = $name;
$this->_required = $required;
$this->_say = isset($say) ? $say : null;
$this->_timeout = $timeout;
$this->_voice = $voice;
$this->_allowSignals = $allowSignals;
$this->_recognizer = $recognizer;
$this->_interdigitTimeout = $interdigitTimeout;
$this->_sensitivity = $sensitivity;
$this->_speechCompleteTimeout = $speechCompleteTimeout;
$this->_speechIncompleteTimeout = $speechIncompleteTimeout;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_attempts)) { $this->attempts = $this->_attempts; }
if(isset($this->_bargein)) { $this->bargein = $this->_bargein; }
if(isset($this->_choices)) { $this->choices = $this->_choices; }
if(isset($this->_minConfidence)) { $this->minConfidence = $this->_minConfidence; }
if(isset($this->_name)) { $this->name = $this->_name; }
if(isset($this->_required)) { $this->required = $this->_required; }
if(isset($this->_say)) { $this->say = $this->_say; }
if (is_array($this->_say)) {
foreach ($this->_say as $k => $v) {
$this->_say[$k] = sprintf('%s', $v);
}
}
if(isset($this->_timeout)) { $this->timeout = $this->_timeout; }
if(isset($this->_voice)) { $this->voice = $this->_voice; }
if(isset($this->_allowSignals)) { $this->allowSignals = $this->_allowSignals; }
if(isset($this->_recognizer)) { $this->recognizer = $this->_recognizer; }
if(isset($this->_interdigitTimeout)) { $this->interdigitTimeout = $this->_interdigitTimeout; }
if(isset($this->_sensitivity)) { $this->sensitivity = $this->_sensitivity; }
if(isset($this->_speechCompleteTimeout)) { $this->speechCompleteTimeout = $this->_speechCompleteTimeout; }
if(isset($this->_speechIncompleteTimeout)) { $this->speechIncompleteTimeout = $this->_speechIncompleteTimeout; }
return $this->unescapeJSON(json_encode($this));
}
/**
* Adds an additional Say to the Ask
*
* Used to add events such as a prompt to say on timeout or nomatch
*
* @param Say $say A say object
*/
public function addEvent(Say $say) {
$this->_say[] = $say;
}
}
/**
* This object allows Tropo to make an outbound call. The call can be over voice or one
* of the text channels.
* @package TropoPHP_Support
*
*/
class Call extends BaseClass {
private $_to;
private $_from;
private $_network;
private $_channel;
private $_answerOnMedia;
private $_timeout;
private $_headers;
private $_recording;
private $_allowSignals;
private $_machineDetection;
private $_voice;
/**
* Class constructor
*
* @param string $to
* @param string $from
* @param string $network
* @param string $channel
* @param boolean $answerOnMedia
* @param int $timeout
* @param array $headers
* @param StartRecording $recording
* @param string|array $allowSignals
*/
public function __construct($to, $from=NULL, $network=NULL, $channel=NULL, $answerOnMedia=NULL, $timeout=NULL, Array $headers=NULL, StartRecording $recording=NULL, $allowSignals=NULL, $machineDetection=NULL, $voice=NULL) {
$this->_to = $to;
$this->_from = $from;
$this->_network = $network;
$this->_channel = $channel;
$this->_answerOnMedia = $answerOnMedia;
$this->_timeout = $timeout;
$this->_headers = $headers;
$this->_recording = isset($recording) ? sprintf('%s', $recording) : null ;
$this->_allowSignals = $allowSignals;
$this->_machineDetection = $machineDetection;
$this->_voice = $voice;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->to = $this->_to;
if(isset($this->_from)) { $this->from = $this->_from; }
if(isset($this->_network)) { $this->network = $this->_network; }
if(isset($this->_channel)) { $this->channel = $this->_channel; }
if(isset($this->_timeout)) { $this->timeout = $this->_timeout; }
if(isset($this->_answerOnMedia)) { $this->answerOnMedia = $this->_answerOnMedia; }
if(count($this->_headers)) { $this->headers = $this->_headers; }
if(isset($this->_recording)) { $this->recording = $this->_recording; }
if(isset($this->_allowSignals)) { $this->allowSignals = $this->_allowSignals; }
if(isset($this->_machineDetection)) {
if(is_bool($this->_machineDetection)){
$this->machineDetection = $this->_machineDetection;
}else{
$this->machineDetection->introduction = $this->_machineDetection;
if(isset($this->_voice)){
$this->machineDetection->voice = $this->_voice;
}
}
}
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Defines the input to be collected from the user.
* @package TropoPHP_Support
*/
class Choices extends BaseClass {
private $_value;
private $_mode;
private $_terminator;
/**
* Class constructor
*
* @param string $value
* @param string $mode
* @param string $terminator
*/
public function __construct($value=NULL, $mode=NULL, $terminator=NULL) {
$this->_value = $value;
$this->_mode = $mode;
$this->_terminator = $terminator;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_value)){ $this->value = $this->_value; }
if(isset($this->_mode)) { $this->mode = $this->_mode; }
if(isset($this->_terminator)) { $this->terminator = $this->_terminator; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* This object allows multiple lines in separate sessions to be conferenced together so that
* the parties on each line can talk to each other simultaneously.
* This is a voice channel only feature.
*
* TODO: Conference object should support multiple event handlers (e.g. join and leave).
* @package TropoPHP_Support
*
*/
class Conference extends BaseClass {
private $_id;
private $_mute;
private $_name;
private $_on;
private $_playTones;
private $_required;
private $_terminator;
private $_allowSignals;
private $_interdigitTimeout;
private $_joinPrompt;
private $_leavePrompt;
private $_voice;
/**
* Class constructor
*
* @param int $id
* @param boolean $mute
* @param string $name
* @param On $on
* @param boolean $playTones
* @param boolean $required
* @param string $terminator
* @param string|array $allowSignals
* @param int $interdigitTimeout
*/
public function __construct($name, $id=NULL, $mute=NULL, On $on=NULL, $playTones=NULL, $required=NULL, $terminator=NULL, $allowSignals=NULL, $interdigitTimeout=NULL, $joinPrompt=NULL, $leavePrompt=NULL, $voice=NULL) {
$this->_name = $name;
$this->_id = (string) $id;
$this->_mute = $mute;
$this->_on = isset($on) ? sprintf('%s', $on) : null;
$this->_playTones = $playTones;
$this->_required = $required;
$this->_terminator = $terminator;
$this->_allowSignals = $allowSignals;
$this->_interdigitTimeout = $interdigitTimeout;
$this->_joinPrompt = $joinPrompt;
$this->_leavePrompt = $leavePrompt;
$this->_voice = $voice;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->name = $this->_name;
if(isset($this->_id)) { $this->id = $this->_id; }
if(isset($this->_mute)) { $this->mute = $this->_mute; }
if(isset($this->_on)) { $this->on = $this->_on; }
if(isset($this->_playTones)) { $this->playTones = $this->_playTones; }
if(isset($this->_required)) { $this->required = $this->_required; }
if(isset($this->_terminator)) { $this->terminator = $this->_terminator; }
if(isset($this->_allowSignals)) { $this->allowSignals = $this->_allowSignals; }
if(isset($this->_interdigitTimeout)) { $this->interdigitTimeout = $this->_interdigitTimeout; }
if(isset($this->_joinPrompt)) {
if($this->_joinPrompt == true || $this->_joinPrompt == false){
$this->joinPrompt = $this->_joinPrompt;
}else{
$this->joinPrompt->value = $this->_joinPrompt;
if(isset($this->_voice)) {
$this->joinPrompt->voice = $this->_voice;
}
}
}
if(isset($this->_leavePrompt)) {
if($this->_leavePrompt == true || $this->_leavePrompt == false){
$this->leavePrompt = $this->_leavePrompt;
}else{
$this->leavePrompt->value = $this->_leavePrompt;
if(isset($this->_voice)) {
$this->leavePrompt->voice = $this->_voice;
}
}
}
return $this->unescapeJSON(json_encode($this));
}
}
/**
* This function instructs Tropo to "hang-up" or disconnect the session associated with the current session.
* @package TropoPHP_Support
*
*/
class Hangup extends EmptyBaseClass { }
/**
* This function instructs Tropo to send a message.
* @package TropoPHP_Support
*
*/
class Message extends BaseClass {
private $_say;
private $_to;
private $_channel;
private $_network;
private $_from;
private $_voice;
private $_timeout;
private $_answerOnMedia;
private $_headers;
/**
* Class constructor
*
* @param Say $say
* @param string $to
* @param string $channel
* @param string $network
* @param string $from
* @param string $voice
* @param integer $timeout
* @param boolean $answerOnMedia
* @param array $headers
*/
public function __construct(Say $say, $to, $channel=null, $network=null, $from=null, $voice=null, $timeout=null, $answerOnMedia=null, Array $headers=null) {
$this->_say = isset($say) ? sprintf('%s', $say) : null ;
$this->_to = $to;
$this->_channel = $channel;
$this->_network = $network;
$this->_from = $from;
$this->_voice = $voice;
$this->_timeout = $timeout;
$this->_answerOnMedia = $answerOnMedia;
$this->_headers = $headers;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->say = $this->_say;
$this->to = $this->_to;
if(isset($this->_channel)) { $this->channel = $this->_channel; }
if(isset($this->_network)) { $this->network = $this->_network; }
if(isset($this->_from)) { $this->from = $this->_from; }
if(isset($this->_voice)) { $this->voice = $this->_voice; }
if(isset($this->_timeout)) { $this->timeout = $this->_timeout; }
if(isset($this->_answerOnMedia)) { $this->answerOnMedia = $this->_answerOnMedia; }
if(count($this->_headers)) { $this->headers = $this->_headers; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Adds an event callback so that your application may be notified when a particular event occurs.
* @package TropoPHP_Support
*
*/
class On extends BaseClass {
private $_event;
private $_next;
private $_say;
private $_voice;
private $_ask;
private $_message;
private $_wait;
private $_order;
/**
* Class constructor
*
* @param string $event
* @param string $next
* @param Say $say
* @param string $voice
*/
public function __construct($event=NULL, $next=NULL, Say $say=NULL, $voice=Null, $ask=NULL, Message $message=NULL, Wait $wait=NULL, $order=NULL) {
$this->_event = $event;
$this->_next = $next;
$this->_say = isset($say) ? sprintf('%s', $say) : null ;
$this->_voice = $voice;
$this->_ask = isset($ask) ? sprintf('%s', $ask) : null;
$this->_message = isset($message) ? sprintf('%s', $message) : null;
$this->_wait = isset($wait) ? sprintf('%s', $wait) : null;
$this->_order = $order;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if($this->_event == "connect") {
$this->event = $this->_event;
switch($this->_order){
case 'ask':
$this->ask = $this->_ask;
break;
case 'say':
$this->say = $this->_say;
break;
case 'wait':
$this->ask = $this->_ask;
break;
case 'message':
$this->message = $this->_message;
break;
}
return $this->unescapeJSON(json_encode(($this)));
}else{
if(isset($this->_event)) { $this->event = $this->_event; }
if(isset($this->_next)) { $this->next = $this->_next; }
if(isset($this->_say)) { $this->say = $this->_say; }
if(isset($this->_voice)) { $this->voice = $this->_voice; }
return $this->unescapeJSON(json_encode($this));
}
}
}
/**
* Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded.
* @package TropoPHP_Support
*
*/
class Record extends BaseClass {
private $_attempts;
private $_allowSignals;
private $_bargein;
private $_beep;
private $_choices;
private $_format;
private $_maxSilence;
private $_maxTime;
private $_method;
private $_password;
private $_required;
private $_say;
private $_timeout;
private $_transcription;
private $_username;
private $_url;
private $_voice;
private $_minConfidence;
private $_interdigitTimeout;
/**
* Class constructor
*
* @param int $attempts
* @param string|array $allowSignals
* @param boolean $bargein
* @param boolean $beep
* @param Choices $choices
* @param string $format
* @param int $maxSilence
* @param string $method
* @param string $password
* @param boolean $required
* @param Say $say
* @param int $timeout
* @param string $username
* @param string $url
* @param string $voice
* @param int $minConfidence
* @param int $interdigitTimeout
*/
public function __construct($attempts=NULL, $allowSignals=NULL, $bargein=NULL, $beep=NULL, Choices $choices=NULL, $format=NULL, $maxSilence=NULL, $maxTime=NULL, $method=NULL, $password=NULL, $required=NULL, $say=NULL, $timeout=NULL, Transcription $transcription=NULL, $username=NULL, $url=NULL, $voice=NULL, $minConfidence=NULL, $interdigitTimeout=NULL) {
$this->_attempts = $attempts;
$this->_allowSignals = $allowSignals;
$this->_bargein = $bargein;
$this->_beep = $beep;
$this->_choices = isset($choices) ? sprintf('%s', $choices) : null;
$this->_format = $format;
$this->_maxSilence = $maxSilence;
$this->_maxTime = $maxTime;
$this->_method = $method;
$this->_password = $password;
if (!is_object($say)) {
$say = new Say($say);
}
$this->_say = isset($say) ? sprintf('%s', $say) : null;
$this->_timeout = $timeout;
$this->_transcription = isset($transcription) ? sprintf('%s', $transcription) : null;
$this->_username = $username;
$this->_url = $url;
$this->_voice = $voice;
$this->_minConfidence = $minConfidence;
$this->_interdigitTimeout = $interdigitTimeout;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_attempts)) { $this->attempts = $this->_attempts; }
if(isset($this->_allowSignals)) { $this->allowSignals = $this->_allowSignals; }
if(isset($this->_bargein)) { $this->bargein = $this->_bargein; }
if(isset($this->_beep)) { $this->beep = $this->_beep; }
if(isset($this->_choices)) { $this->choices = $this->_choices; }
if(isset($this->_format)) { $this->format = $this->_format; }
if(isset($this->_maxSilence)) { $this->maxSilence = $this->_maxSilence; }
if(isset($this->_maxTime)) { $this->maxTime = $this->_maxTime; }
if(isset($this->_method)) { $this->method = $this->_method; }
if(isset($this->_password)) { $this->password = $this->_password; }
if(isset($this->_say)) { $this->say = $this->_say; }
if(isset($this->_timeout)) { $this->timeout = $this->_timeout; }
if(isset($this->_transcription)) { $this->transcription = $this->_transcription; }
if(isset($this->_username)) { $this->username = $this->_username; }
if(isset($this->_url)) { $this->url = $this->_url; }
if(isset($this->_voice)) { $this->voice = $this->_voice; }
if(isset($this->_minConfidence)) { $this->minConfidence = $this->_minConfidence; }
if(isset($this->_interdigitTimeout)) { $this->interdigitTimeout = $this->_interdigitTimeout; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* The redirect function forwards an incoming call to another destination / phone number before answering it.
* @package TropoPHP_Support
*
*/
class Redirect extends BaseClass {
private $_to;
private $_from;
/**
* Class constructor
*
* @param Endpoint $to
* @param Endpoint $from
*/
public function __construct($to=NULL, $from=NULL) {
$this->_to = sprintf('%s', $to);
$this->_from = isset($from) ? sprintf('%s', $from) : null;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->to = $this->_to;
if(isset($this->_from)) { $this->from = $this->_from; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Allows Tropo applications to reject incoming sessions before they are answered.
* @package TropoPHP_Support
*
*/
class Reject extends EmptyBaseClass { }
/**
* Returned anytime a request is made to the Tropo Web API.
* @package TropoPHP
*
*/
class Result {
private $_sessionId;
private $_callId;
private $_state;
private $_sessionDuration;
private $_sequence;
private $_complete;
private $_error;
private $_actions;
private $_name;
private $_attempts;
private $_disposition;
private $_confidence;
private $_interpretation;
private $_concept;
private $_userType;
private $_utterance;
private $_value;
private $_transcription;
/**
* Class constructor
*
* @param string $json
*/
public function __construct($json=NULL) {
if(empty($json)) {
$json = file_get_contents("php://input");
// if $json is still empty, there was nothing in
// the POST so throw an exception
if(empty($json)) {
throw new TropoException('No JSON available.');
}
}
$result = json_decode($json);
if (!is_object($result) || !property_exists($result, "result")) {
throw new TropoException('Not a result object.');
}
$this->_sessionId = $result->result->sessionId;
$this->_callId = $result->result->callId;
$this->_state = $result->result->state;
$this->_sessionDuration = $result->result->sessionDuration;
$this->_sequence = $result->result->sequence;
$this->_complete = $result->result->complete;
$this->_error = $result->result->error;
$this->_userType = $result->result->userType;
$this->_actions = $result->result->actions;
$this->_name = $result->result->actions->name;
$this->_attempts = $result->result->actions->attempts;
$this->_disposition = $result->result->actions->disposition;
$this->_confidence = $result->result->actions->confidence;
$this->_interpretation = $result->result->actions->interpretation;
$this->_utterance = $result->result->actions->utterance;
$this->_value = $result->result->actions->value;
$this->_concept = isset($result->result->actions->concept) ? $result->result->actions->concept : null;
$this->_transcription = isset($result->result->transcription) ? $result->result->transcription : null;
}
public function getSessionId() {
return $this->_sessionId;
}
public function getCallId() {
return $this->_callId;
}
public function getState() {
return $this->_state;
}
public function getSessionDuration() {
return $this->_sessionDuration;
}
public function getSequence() {
return $this->_sequence;
}
public function isComplete() {
return (bool) $this->_complete;
}
public function getError() {
return $this->_error;
}
public function getUserType() {
return $this->_userType;
}
public function getActions() {
return $this->_actions;
}
public function getName() {
return $this->_name;
}
public function getAttempts() {
return $this->_attempts;
}
public function getDisposition() {
return $this->_disposition;
}
public function getConfidence() {
return $this->_confidence;
}
public function getInterpretation() {
return $this->_interpretation;
}
public function getConcept() {
return $this->_concept;
}
public function getUtterance() {
return $this->_utterance;
}
public function getValue() {
return $this->_value;
}
public function getTranscription() {
return $this->_transcription;
}
}
/**
* 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 instant messaging or SMS.
* @package TropoPHP_Support
*
*/
class Say extends BaseClass {
private $_value;
private $_as;
private $_event;
private $_format;
private $_voice;
private $_allowSignals;
/**
* Class constructor
*
* @param string $value
* @param SayAs $as
* @param string $event
* @param string $voice
* @param string|array $allowSignals
*/
public function __construct($value, $as=NULL, $event=NULL, $voice=NULL, $allowSignals=NULL) {
$this->_value = $value;
$this->_as = $as;
$this->_event = $event;
$this->_voice = $voice;
$this->_allowSignals = $allowSignals;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_event)) { $this->event = $this->_event; }
$this->value = $this->_value;
if(isset($this->_as)) { $this->as = $this->_as; }
if(isset($this->_voice)) { $this->voice = $this->_voice; }
if(isset($this->_allowSignals)) { $this->allowSignals = $this->_allowSignals; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* The payload sent as an HTTP POST to the web application when a new session arrives.
*
* TODO: Consider using associative array for To and From.
* TODO: Need to break out headers into a more accessible data structure.
* @package TropoPHP
*/
class Session {
private $_id;
private $_accountId;
private $_callId;
private $_timestamp;
private $_initialText;
private $_to;
private $_from;
private $_headers;
private $_parameters;
/**
* Class constructor
*
* @param string $json
*/
public function __construct($json=NULL) {
if(empty($json)) {
$json = file_get_contents("php://input");
// if $json is still empty, there was nothing in
// the POST so throw exception
if(empty($json)) {
throw new TropoException('No JSON available.', 1);
}
}
$session = json_decode($json);
if (!is_object($session) || !property_exists($session, "session")) {
throw new TropoException('Not a session object.', 2);
}
$this->_id = $session->session->id;
$this->_accountId = $session->session->accountId;
$this->_callId = $session->session->callId;
$this->_timestamp = $session->session->timestamp;
$this->_initialText = $session->session->initialText;
$this->_to = isset($session->session->to)
? array(
"id" => $session->session->to->id,
"channel" => $session->session->to->channel,
"name" => $session->session->to->name,
"network" => $session->session->to->network
)
: array(
"id" => null,
"channel" => null,
"name" => null,
"network" => null
);
$this->_from = isset($session->session->from->id)
? array(
"id" => $session->session->from->id,
"channel" => $session->session->from->channel,
"name" => $session->session->from->name,
"network" => $session->session->from->network
)
: array(
"id" => null,
"channel" => null,
"name" => null,
"network" => null
);
$this->_headers = isset($session->session->headers)
? self::setHeaders($session->session->headers)
: array();
$this->_parameters = property_exists($session->session, 'parameters') ? (Array) $session->session->parameters : null;
}
public function getId() {
return $this->_id;
}
public function getAccountID() {
return $this->_accountId;
}
public function getCallId() {
return $this->_callId;
}
public function getTimeStamp() {
return $this->_timestamp;
}
public function getInitialText() {
return $this->_initialText;
}
public function getTo() {
return $this->_to;
}
public function getFrom() {
return $this->_from;
}
function getFromChannel() {
return $this->_from['channel'];
}
function getFromNetwork() {
return $this->_from['network'];
}
public function getHeaders() {
return $this->_headers;
}
/**
* Returns the query string parameters for the session api
*
* If an argument is provided, a string containing the value of a
* query string variable matching that string is returned or null
* if there is no match. If no argument is argument is provided,
* an array is returned with all query string variables or an empty
* array if there are no query string variables.
*
* @param string $name A specific parameter to return
* @return string|array $param
*/
public function getParameters($name = null) {
if (isset($name)) {
if (!is_array($this->_parameters)) {
// We've asked for a specific param, not there's no params set
// return a null.
return null;
}
if (isset($this->_parameters[$name])) {
return $this->_parameters[$name];
} else {
return null;
}
} else {
// If the parameters field doesn't exist or isn't an array
// then return an empty array()
if (!is_array($this->_parameters)) {
return array();
}
return $this->_parameters;
}
}
public function setHeaders($headers) {
$formattedHeaders = new Headers();
// headers don't exist on outboud calls
// so only do this if there are headers
if (is_object($headers)) {
foreach($headers as $name => $value) {
$formattedHeaders->$name = $value;
}
}
return $formattedHeaders;
}
}
/**
* Allows Tropo applications to begin recording the current session.
* The resulting recording may then be sent via FTP or an HTTP POST/Multipart Form.
* @package TropoPHP_Support
*
*/
class StartRecording extends BaseClass {
private $_name;
private $_format;
private $_method;
private $_password;
private $_url;
private $_username;
private $_transcriptionID;
private $_transcriptionEmailFormat;
private $_transcriptionOutURI;
/**
* Class constructor
*
* @param string $name
* @param string $format
* @param string $method
* @param string $password
* @param string $url
* @param string $username
* @param string $transcriptionID
* @param string $transcriptionEmailFormat
* @param string $transcriptionOutURI
*/
public function __construct($format=NULL, $method=NULL, $password=NULL, $url=NULL, $username=NULL, $transcriptionID=NULL, $transcriptionEmailFormat=NULL, $transcriptionOutURI=NULL) {
$this->_format = $format;
$this->_method = $method;
$this->_password = $password;
$this->_url = $url;
$this->_username = $username;
$this->_transcriptionID = $transcriptionID;
$this->_transcriptionEmailFormat = $transcriptionEmailFormat;
$this->_transcriptionOutURI = $transcriptionOutURI;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_format)) { $this->format = $this->_format; }
if(isset($this->_method)) { $this->method = $this->_method; }
if(isset($this->_password)) { $this->password = $this->_password; }
if(isset($this->_url)) { $this->url = $this->_url; }
if(isset($this->_username)) { $this->username = $this->_username; }
if(isset($this->_transcriptionID)) { $this->transcriptionID = $this->_transcriptionID; }
if(isset($this->_transcriptionEmailFormat)) { $this->transcriptionEmailFormat = $this->_transcriptionEmailFormat; }
if(isset($this->_transcriptionOutURI)) { $this->transcriptionOutURI = $this->_transcriptionOutURI; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Stop an already started recording.
* @package TropoPHP_Support
*
*/
class StopRecording extends EmptyBaseClass { }
/**
* Transcribes spoken text.
* @package TropoPHP_Support
*
*/
class Transcription extends BaseClass {
private $_url;
private $_id;
private $_emailFormat;
/**
* Class constructor
*
* @param string $url
* @param string $id
* @param string $emailFormat
*/
public function __construct($url, $id=NULL, $emailFormat=NULL) {
$this->_url = $url;
$this->_id = $id;
$this->_emailFormat = $emailFormat;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_id)) { $this->id = $this->_id; }
if(isset($this->_url)) { $this->url = $this->_url; }
if(isset($this->_emailFormat)) { $this->emailFormat = $this->_emailFormat; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Transfers an already answered call to another destination / phone number.
* @package TropoPHP_Support
*
*/
class Transfer extends BaseClass {
private $_answerOnMedia;
private $_choices;
private $_from;
private $_on;
private $_ringRepeat;
private $_timeout;
private $_to;
private $_allowSignals;
private $_headers;
private $_machineDetection;
private $_voice;
/**
* Class constructor
*
* @param string $to
* @param boolean $answerOnMedia
* @param Choices $choices
* @param Endpoint $from
* @param On $on
* @param int $ringRepeat
* @param int $timeout
* @param string|array $allowSignals
* @param array $headers
*/
public function __construct($to, $answerOnMedia=NULL, Choices $choices=NULL, $from=NULL, $ringRepeat=NULL, $timeout=NULL, $on=NULL, $allowSignals=NULL, Array $headers=NULL, $machineDetection=NULL, $voice=NULL) {
$this->_to = $to;
$this->_answerOnMedia = $answerOnMedia;
$this->_choices = isset($choices) ? sprintf('%s', $choices) : null;
$this->_from = $from;
$this->_ringRepeat = $ringRepeat;
$this->_timeout = $timeout;
$this->_on = isset($on) ? array(sprintf('%s', $on)) : null;
$this->_allowSignals = $allowSignals;
$this->_headers = $headers;
$this->_machineDetection = $machineDetection;
$this->_voice = $voice;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->to = $this->_to;
if(isset($this->_answerOnMedia)) { $this->answerOnMedia = $this->_answerOnMedia; }
if(isset($this->_choices)) { $this->choices = $this->_choices; }
if(isset($this->_from)) { $this->from = $this->_from; }
if(isset($this->_ringRepeat)) { $this->ringRepeat = $this->_ringRepeat; }
if(isset($this->_timeout)) { $this->timeout = $this->_timeout; }
if(isset($this->_on)) { $this->on = $this->_on; }
if(isset($this->_allowSignals)) { $this->allowSignals = $this->_allowSignals; }
if(count($this->_headers)) { $this->headers = $this->_headers; }
if(isset($this->_machineDetection)) {
if(is_bool($this->_machineDetection)){
$this->machineDetection = $this->_machineDetection;
}else{
$this->machineDetection->introduction = $this->_machineDetection;
if(isset($this->_voice)){
$this->machineDetection->voice = $this->_voice;
}
}
}
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Defines a time period to sleep in milliseconds
* @package TropoPHP_Support
*
*/
class Wait extends BaseClass {
private $_milliseconds;
private $_allowSignals;
/**
* Class constructor
*
* @param integer $milliseconds
* @param string|array $allowSignals
*/
public function __construct($milliseconds, $allowSignals=NULL) {
$this->_milliseconds = $milliseconds;
$this->_allowSignals = $allowSignals;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
$this->milliseconds = $this->_milliseconds;
if(isset($this->_allowSignals)) { $this->allowSignals = $this->_allowSignals; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* Defnies an endoint for transfer and redirects.
* @package TropoPHP_Support
*
*/
class Endpoint extends BaseClass {
private $_id;
private $_channel;
private $_name = 'unknown';
private $_network;
/**
* Class constructor
*
* @param string $id
* @param string $channel
* @param string $name
* @param string $network
*/
public function __construct($id, $channel=NULL, $name=NULL, $network=NULL) {
$this->_id = $id;
$this->_channel = $channel;
$this->_name = $name;
$this->_network = $network;
}
/**
* Renders object in JSON format.
*
*/
public function __toString() {
if(isset($this->_id)) { $this->id = $this->_id; }
if(isset($this->_channel)) { $this->channel = $this->_channel; }
if(isset($this->_name)) { $this->name = $this->_name; }
if(isset($this->_network)) { $this->network = $this->_network; }
return $this->unescapeJSON(json_encode($this));
}
}
/**
* A helper class for wrapping exceptions. Can be modified for custom excpetion handling.
*
*/
class TropoException extends Exception { }
/**
* Date Helper class.
* @package TropoPHP_Support
*/
class Date {
public static $monthDayYear = "mdy";
public static $dayMonthYear = "dmy";
public static $yearMonthDay = "ymd";
public static $yearMonth = "ym";
public static $monthYear = "my";
public static $monthDay = "md";
public static $year = "y";
public static $month = "m";
public static $day = "d";
}
/**
* Duration Helper class.
* @package TropoPHP_Support
*/
class Duration {
public static $hoursMinutesSeconds = "hms";
public static $hoursMinutes = "hm";
public static $hours = "h";
public static $minutes = "m";
public static $seconds = "s";
}
/**
* Event Helper class.
* @package TropoPHP_Support
*/
class Event {
public static $continue = 'continue';
public static $incomplete = 'incomplete';
public static $error = 'error';
public static $hangup = 'hangup';
public static $join = 'join';
public static $leave = 'leave';
public static $ring = 'ring';
}
/**
* Format Helper class.
* @package TropoPHP_Support
*/
class Format {
public $date;
public $duration;
public static $ordinal = "ordinal";
public static $digits = "digits";
public function __construct($date=NULL, $duration=NULL) {
$this->date = $date;
$this->duration = $duration;
}
}
/**
* SayAs Helper class.
* @package TropoPHP_Support
*/
class SayAs {
public static $date = "DATE";
public static $digits = "DIGITS";
public static $number = "NUMBER";
}
/**
* Network Helper class.
* @package TropoPHP_Support
*/
class Network {
public static $pstn = "PSTN";
public static $voip = "VOIP";
public static $aim = "AIM";
public static $gtalk = "GTALK";
public static $jabber = "JABBER";
public static $msn = "MSN";
public static $sms = "SMS";
public static $yahoo = "YAHOO";
public static $twitter = "TWITTER";
}
/**
* Channel Helper class.
* @package TropoPHP_Support
*/
class Channel {
public static $voice = "VOICE";
public static $text = "TEXT";
}
/**
* AudioFormat Helper class.
* @package TropoPHP_Support
*/
class AudioFormat {
public static $wav = "audio/wav";
public static $mp3 = "audio/mp3";
}
/**
* Voice Helper class.
* @package TropoPHP_Support
*/
class Voice {
public static $Castilian_Spanish_male = "jorge";
public static $Castilian_Spanish_female = "carmen";
public static $French_male = "bernard";
public static $French_female = "florence";
public static $US_English_male = "dave";
public static $US_English_female = "jill";
public static $British_English_male = "dave";
public static $British_English_female = "kate";
public static $German_male = "stefan";
public static $German_female = "katrin";
public static $Italian_male = "luca";
public static $Italian_female = "paola";
public static $Dutch_male = "willem";
public static $Dutch_female = "saskia";
public static $Mexican_Spanish_male = "carlos";
public static $Mexican_Spanish_female = "soledad";
}
/**
* Recognizer Helper class
* @package TropoPHP_Support
*
*/
class Recognizer {
public static $German = 'de-de';
public static $British_English = 'en-gb';
public static $US_English = 'en-us';
public static $Castilian_Spanish = 'es-es';
public static $Mexican_Spanish = 'es-mx';
public static $French_Canadian = 'fr-ca';
public static $French = 'fr-fr';
public static $Italian = 'it-it';
public static $Polish = 'pl-pl';
public static $Dutch = 'nl-nl';
}
/**
* SIP Headers Helper class.
* @package TropoPHP_Support
*/
class Headers {
public function __set($name, $value) {
if(!strstr($name, "-")) {
$this->$name = $value;
} else {
$name = str_replace("-", "_", $name);
$this->$name = $value;
}
}
}
?>
Jump to Line
Something went wrong with that request. Please try again.