Skip to content

Commit

Permalink
New parameter transcriptionLanguage is added for record/startRecordin…
Browse files Browse the repository at this point in the history
…g api for PHP
  • Loading branch information
pengxli committed Aug 21, 2017
1 parent ba7533e commit edd4f77
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 62 deletions.
4 changes: 2 additions & 2 deletions readme.markdown
Expand Up @@ -6,7 +6,7 @@ TropoPHP is a set of PHP classes for working with [Tropo's cloud communication s
Requirements
============

* PHP 5.3.0 or greater (5.4 not yet supported)
* PHP 5.6 or greater
* PHP Notices disabled (All error reporting disabled is recommended for production use)

Usage
Expand All @@ -19,7 +19,7 @@ Answer the phone, say something, and hang up.

$tropo = new Tropo();
// Use Tropo's text to speech to say a phrase.
$tropo->say('Yes, Tropo is this easy.');
$tropo->say('Yes, Tropo is this easy.', array('name' => 'sayName'));

// Render the JSON back to Tropo.
$tropo->renderJSON();
Expand Down
2 changes: 0 additions & 2 deletions tests/CallTest.php
Expand Up @@ -30,7 +30,6 @@ public function testCallWithAllOptions() {
$allowSignals = array('exit', 'quit');
$headers = array('foo' => 'bar', 'bling' => 'baz');
$params = array(
'to' => $to,
'allowSignals' => $allowSignals,
'answerOnMedia' => false,
'channel' => Channel::$voice,
Expand All @@ -56,7 +55,6 @@ public function testCallWithAllOptions1() {
$allowSignals = array('exit', 'quit');
$headers = array('foo' => 'bar', 'bling' => 'baz');
$params = array(
'to' => $to,
'allowSignals' => $allowSignals,
'answerOnMedia' => false,
'channel' => Channel::$voice,
Expand Down
2 changes: 1 addition & 1 deletion tests/HangupTest.php
@@ -1,5 +1,5 @@
<?php
require_once 'PHPUnit/Framework.php';
use PHPUnit\Framework\TestCase;
require_once 'tropo.class.php';

class HangupTest extends PHPUnit_Framework_TestCase
Expand Down
23 changes: 0 additions & 23 deletions tests/OnTest.php
Expand Up @@ -26,16 +26,6 @@ public function testCreateOnObject1() {
$this->assertEquals(sprintf($tropo), '{"tropo":[{"on":[{"event":"continue","next":"say.php","say":{"value":"array continue!"}}]}]}');
}

public function testFailsOnWithNoEventParameter() {
$tropo = new Tropo();
try {
$say = new Say("object continue!");
@ $on = new On();
} catch (Exception $e) {
$this->assertEquals($e->getMessage(), "Missing required property: 'event'");
}
}

public function testFailsOnWithNoEventParameter1() {
$tropo = new Tropo();
try {
Expand Down Expand Up @@ -100,19 +90,6 @@ public function testFailsOnWithNoEventParameter5() {
}
}

public function testFailsOnWithNoSayParameter1() {
$tropo = new Tropo();
try {
$on = array(
'event' => Event::$continue,
'next' => 'say.php'
);
$tropo->on($on);
} catch (Exception $e) {
$this->assertEquals($e->getMessage(), "Property: 'say' must be a Say of array or an instance of Say.");
}
}

public function testFailsOnWithNoSayParameter2() {
$tropo = new Tropo();
try {
Expand Down
9 changes: 5 additions & 4 deletions tests/RecordTest.php
Expand Up @@ -24,7 +24,8 @@ public function testRecordWithAllOptions() {
$transcription = array(
'id' => '1234',
'url' => 'mailto:you@yourmail.com',
'emailFormat' => 'omit'
'emailFormat' => 'omit',
'language' => 'en-uk'
);
$record = array(
'attempts' => 2,
Expand All @@ -51,7 +52,7 @@ public function testRecordWithAllOptions() {
'promptLogSecurity' => 'suppress'
);
$tropo->record($record);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"attempts":2,"allowSignals":["exit","quit"],"bargein":true,"beep":true,"choices":{"terminator":"*"},"format":"audio/mp3","maxSilence":5,"maxTime":30,"method":"POST","password":"111111","required":true,"say":[{"value":"Please leave a message."},{"event":"timeout","value":"Sorry, I did not hear anything. Please call back."}],"timeout":30,"transcription":{"id":"1234","url":"mailto:you@yourmail.com","emailFormat":"omit"},"username":"root","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","voice":"allison","interdigitTimeout":5,"asyncUpload":false,"name":"foo","promptLogSecurity":"suppress"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"attempts":2,"allowSignals":["exit","quit"],"bargein":true,"beep":true,"choices":{"terminator":"*"},"format":"audio/mp3","maxSilence":5,"maxTime":30,"method":"POST","password":"111111","required":true,"say":[{"value":"Please leave a message."},{"event":"timeout","value":"Sorry, I did not hear anything. Please call back."}],"timeout":30,"transcription":{"id":"1234","url":"mailto:you@yourmail.com","emailFormat":"omit","language":"en-uk"},"username":"root","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","voice":"allison","interdigitTimeout":5,"asyncUpload":false,"name":"foo","promptLogSecurity":"suppress"}}]}');
}


Expand All @@ -70,10 +71,10 @@ public function testCreateObject() {
new Say("Please leave a message."),
new Say("Sorry, I did not hear anything. Please call back.", null , "timeout")
);
$transcription = new Transcription("mailto:you@yourmail.com", "1234", "omit");
$transcription = new Transcription("mailto:you@yourmail.com", "1234", "omit", "en-uk");
$record = new Record(2, $allowSignals, true, true, $choices, AudioFormat::$mp3, 5.0, 30.0, "POST", "111111", true, $say, 30.0, $transcription, "root", "http://192.168.26.203/tropo-webapi-php/upload_file.php", Voice::$US_English_female_allison, null, 5.0, false, "foo", "suppress");
$tropo->record($record);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"attempts":2,"allowSignals":["exit","quit"],"bargein":true,"beep":true,"choices":{"terminator":"*"},"format":"audio/mp3","maxSilence":5,"maxTime":30,"method":"POST","password":"111111","required":true,"say":[{"value":"Please leave a message."},{"event":"timeout","value":"Sorry, I did not hear anything. Please call back."}],"timeout":30,"transcription":{"id":"1234","url":"mailto:you@yourmail.com","emailFormat":"omit"},"username":"root","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","voice":"allison","interdigitTimeout":5,"asyncUpload":false,"name":"foo","promptLogSecurity":"suppress"}}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"attempts":2,"allowSignals":["exit","quit"],"bargein":true,"beep":true,"choices":{"terminator":"*"},"format":"audio/mp3","maxSilence":5,"maxTime":30,"method":"POST","password":"111111","required":true,"say":[{"value":"Please leave a message."},{"event":"timeout","value":"Sorry, I did not hear anything. Please call back."}],"timeout":30,"transcription":{"id":"1234","url":"mailto:you@yourmail.com","emailFormat":"omit","language":"en-uk"},"username":"root","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","voice":"allison","interdigitTimeout":5,"asyncUpload":false,"name":"foo","promptLogSecurity":"suppress"}}]}');
}

public function testRecordWithSensitivity() {
Expand Down
19 changes: 0 additions & 19 deletions tests/SayTest.php
Expand Up @@ -29,15 +29,6 @@ public function testCreateSayObject1()
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"name":"say","required":true,"promptLogSecurity":"suppress"}]}]}');
}

public function testFailsSayWithNoValueParameter()
{
try{
@ $say = new Say();
} catch (Exception $e) {
$this->assertEquals($e->getMessage(), "Missing required property: 'value'");
}
}

public function testFailsSayWithNoValueParameter1()
{
try{
Expand Down Expand Up @@ -89,16 +80,6 @@ public function testFailsSayWithNoNameParameter2()
}
}

public function testFailsSayWithNoValueParameter3()
{
$tropo = new Tropo();
try{
@ $tropo->say();
} catch (Exception $e) {
$this->assertEquals($e->getMessage(), "Argument 1 passed to Tropo::say() must be a string or an instance of Say.");
}
}

public function testFailsSayWithNoValueParameter4()
{
$tropo = new Tropo();
Expand Down
2 changes: 1 addition & 1 deletion tests/SessionTest.php
@@ -1,6 +1,6 @@
<?php
use PHPUnit\Framework\TestCase;
require_once '../tropo.class.php';
require_once 'tropo.class.php';

class OnTest extends TestCase{

Expand Down
9 changes: 5 additions & 4 deletions tests/StartRecordingTest.php
Expand Up @@ -27,13 +27,14 @@ public function testRecordWithAllOptions() {
'password' => '111111',
'transcriptionOutURI' => 'mailto:you@yourmail.com',
'transcriptionEmailFormat' => 'plain',
'transcriptionID' => '1234'
'transcriptionID' => '1234',
'transcriptionLanguage' => 'pt-br'
);
$tropo->startRecording($startRecording);
$say = new Say("I am now recording!", null, null, null, null, "say");
$tropo->say($say);
$tropo->stopRecording();
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"format":"audio/au","method":"POST","password":"111111","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","transcriptionID":"1234","transcriptionEmailFormat":"plain","transcriptionOutURI":"mailto:you@yourmail.com","asyncUpload":false}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"format":"audio/au","method":"POST","password":"111111","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","transcriptionID":"1234","transcriptionEmailFormat":"plain","transcriptionOutURI":"mailto:you@yourmail.com","transcriptionLanguage":"pt-br","asyncUpload":false}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
}

public function testCreateMinObject() {
Expand All @@ -48,12 +49,12 @@ public function testCreateMinObject() {

public function testCreateObject() {
$tropo = new Tropo();
$startRecording = new StartRecording(AudioFormat::$mp3, "POST", "111111", "http://192.168.26.203/tropo-webapi-php/upload_file.php", "root", "1234", "plain", "mailto:you@yourmail.com", false);
$startRecording = new StartRecording(AudioFormat::$mp3, "POST", "111111", "http://192.168.26.203/tropo-webapi-php/upload_file.php", "root", "1234", "plain", "mailto:you@yourmail.com", false, "pt-br");
$tropo->startRecording($startRecording);
$say = new Say("I am now recording!", null, null, null, null, "say");
$tropo->say($say);
$tropo->stopRecording();
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"format":"audio/mp3","method":"POST","password":"111111","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","transcriptionID":"1234","transcriptionEmailFormat":"plain","transcriptionOutURI":"mailto:you@yourmail.com","asyncUpload":false}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"format":"audio/mp3","method":"POST","password":"111111","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","transcriptionID":"1234","transcriptionEmailFormat":"plain","transcriptionOutURI":"mailto:you@yourmail.com","transcriptionLanguage":"pt-br","asyncUpload":false}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
}

}
Expand Down
20 changes: 14 additions & 6 deletions tropo.class.php
Expand Up @@ -552,14 +552,14 @@ public function record($record) {
$params['voice'] = $this->_voice;
}
if (is_array($params['transcription'])) {
$p = array('url', 'id', 'emailFormat');
$p = array('url', 'id', 'emailFormat', 'language');
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"]);
$transcription = new Transcription($params["transcription"]["url"],$params["transcription"]["id"],$params["transcription"]["emailFormat"],$params["transcription"]["language"]);
} else {
$transcription = $params["transcription"];
}
Expand Down Expand Up @@ -768,14 +768,14 @@ public function startRecording($startRecording) {
}

$params = $startRecording;
$p = array('format', 'method', 'password', 'url', 'username', 'transcriptionID', 'transcriptionEmailFormat', 'transcriptionOutURI', 'asyncUpload');
$p = array('format', 'method', 'password', 'url', 'username', 'transcriptionID', 'transcriptionEmailFormat', 'transcriptionOutURI', 'asyncUpload', 'transcriptionLanguage');
foreach ($p as $option) {
$$option = null;
if (array_key_exists($option, $params)) {
$$option = $params[$option];
}
}
$startRecording = new StartRecording($format, $method, $password, $url, $username, $transcriptionID, $transcriptionEmailFormat, $transcriptionOutURI, $asyncUpload);
$startRecording = new StartRecording($format, $method, $password, $url, $username, $transcriptionID, $transcriptionEmailFormat, $transcriptionOutURI, $asyncUpload, $transcriptionLanguage);

} else {

Expand Down Expand Up @@ -2560,6 +2560,7 @@ class StartRecording extends BaseClass {
private $_transcriptionID;
private $_transcriptionEmailFormat;
private $_transcriptionOutURI;
private $_transcriptionLanguage;
private $_asyncUpload;

public function getUrl() {
Expand All @@ -2578,8 +2579,9 @@ public function getUrl() {
* @param string $transcriptionID
* @param string $transcriptionEmailFormat
* @param string $transcriptionOutURI
* @param string $transcriptionLanguage
*/
public function __construct($format=NULL, $method=NULL, $password=NULL, $url, $username=NULL, $transcriptionID=NULL, $transcriptionEmailFormat=NULL, $transcriptionOutURI=NULL, $asyncUpload=NULL) {
public function __construct($format=NULL, $method=NULL, $password=NULL, $url, $username=NULL, $transcriptionID=NULL, $transcriptionEmailFormat=NULL, $transcriptionOutURI=NULL, $asyncUpload=NULL, $transcriptionLanguage=NULL) {
if(!isset($url)) {
throw new Exception("Missing required property: 'url'");
}
Expand All @@ -2594,6 +2596,7 @@ public function __construct($format=NULL, $method=NULL, $password=NULL, $url, $u
$this->_transcriptionID = $transcriptionID;
$this->_transcriptionEmailFormat = $transcriptionEmailFormat;
$this->_transcriptionOutURI = $transcriptionOutURI;
$this->_transcriptionLanguage = $transcriptionLanguage;
$this->_asyncUpload = $asyncUpload;
}

Expand All @@ -2610,6 +2613,7 @@ public function __toString() {
if(isset($this->_transcriptionID)) { $this->transcriptionID = $this->_transcriptionID; }
if(isset($this->_transcriptionEmailFormat)) { $this->transcriptionEmailFormat = $this->_transcriptionEmailFormat; }
if(isset($this->_transcriptionOutURI)) { $this->transcriptionOutURI = $this->_transcriptionOutURI; }
if(isset($this->_transcriptionLanguage)) { $this->transcriptionLanguage = $this->_transcriptionLanguage; }
if(isset($this->_asyncUpload)) { $this->asyncUpload = $this->_asyncUpload; }
return json_encode($this);
}
Expand All @@ -2632,18 +2636,21 @@ class Transcription extends BaseClass {
private $_url;
private $_id;
private $_emailFormat;
private $_language;

/**
* Class constructor
*
* @param string $url
* @param string $id
* @param string $emailFormat
* @param string $language
*/
public function __construct($url, $id=NULL, $emailFormat=NULL) {
public function __construct($url, $id=NULL, $emailFormat=NULL, $language=NULL) {
$this->_url = $url;
$this->_id = $id;
$this->_emailFormat = $emailFormat;
$this->_language = $language;
}

/**
Expand All @@ -2654,6 +2661,7 @@ 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; }
if(isset($this->_language)) { $this->language = $this->_language; }
return json_encode($this);
}
}
Expand Down

0 comments on commit edd4f77

Please sign in to comment.