Skip to content

Commit

Permalink
TROPO-13424 add MMS support
Browse files Browse the repository at this point in the history
  • Loading branch information
pengxli committed Aug 10, 2018
1 parent af88e52 commit 9144837
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 4 deletions.
16 changes: 16 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ public function testMessageWithMinOptions() {
$this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":{"value":"This is an announcement."},"to":"sip:[email protected]:5678"}}]}');
}

public function testMessageWithMMS() {
$tropo = new Tropo();
$say = new Say("This is the subject",null, null, null, null, null,null,null,"http://user:[email protected]/1.jpg");
$message = new Message($say,'sip:[email protected]:5678',null, Network::$mms);
$tropo->message($message);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":{"value":"This is the subject","media":"http://user:[email protected]/1.jpg"},"to":"sip:[email protected]:5678","network":"MMS"}}]}');
}

public function testMessageWithMMS1() {
$tropo = new Tropo();
$say = new Say("This is the subject",null, null, null, null, null,null,null,array("http://server.com/1.jpg", "this is a inline text content", "http://filehosting.tropo.com/account/1/2.text"));
$message = new Message($say,'sip:[email protected]:5678',null, Network::$mms);
$tropo->message($message);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":{"value":"This is the subject","media":["http://server.com/1.jpg","this is a inline text content","http://filehosting.tropo.com/account/1/2.text"]},"to":"sip:[email protected]:5678","network":"MMS"}}]}');
}

public function testMessageWithExtraSayOptiions() {
$tropo = new Tropo();
$say = "Remember, you have a meeting at 2 PM.";
Expand Down
62 changes: 62 additions & 0 deletions tests/SayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public function testSayWithOptions() {
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","name":"say"}]}]}');
}

public function testSayWithOptions1() {
$tropo = new Tropo();
$tropo->say("Please enter your account number...",array('name' => 'say','media' => 'http://user:[email protected]/1.jpg'));
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","name":"say","media":"http://user:[email protected]/1.jpg"}]}]}');
}

public function testSayWithOptions2() {
$tropo = new Tropo();
$tropo->say("Please enter your account number...",array('name' => 'say','media' => array('http://server.com/1.jpg', 'this is a inline text content', 'http://filehosting.tropo.com/account/1/2.text')));
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","name":"say","media":["http://server.com/1.jpg","this is a inline text content","http://filehosting.tropo.com/account/1/2.text"]}]}]}');
}

public function testCreateSayObject()
{
$tropo = new Tropo();
Expand All @@ -40,6 +52,56 @@ public function testCreateSayObject1()
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"required":true,"promptLogSecurity":"suppress"}]}]}');
}

public function testCreateSayObject2()
{
$tropo = new Tropo();
$allowSignals = array('exit','quit');
$say = new Say("Please enter your account number...", SayAs::$date, null, Voice::$US_English_female_allison, $allowSignals, null, true, "suppress", "http://user:[email protected]/1.jpg");
$tropo->say($say);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"required":true,"promptLogSecurity":"suppress","media":"http://user:[email protected]/1.jpg"}]}]}');
}

public function testCreateSayObject3()
{
$tropo = new Tropo();
$allowSignals = array('exit','quit');
$say = new Say("Please enter your account number...", SayAs::$date, null, Voice::$US_English_female_allison, $allowSignals, null, true, "suppress", array('http://server.com/1.jpg', 'this is a inline text content', 'http://filehosting.tropo.com/account/1/2.text'));
$tropo->say($say);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"required":true,"promptLogSecurity":"suppress","media":["http://server.com/1.jpg","this is a inline text content","http://filehosting.tropo.com/account/1/2.text"]}]}]}');
}

public function testCreateSayObject4()
{
$tropo = new Tropo();
$allowSignals = array('exit','quit');
$params = array(
"as"=>SayAs::$date,
"event"=>"event",
"voice"=>Voice::$US_English_female_allison,
"allowSignals"=>$allowSignals,
"promptLogSecurity"=>"suppress",
"required"=>true,
"media"=>"http://user:[email protected]/1.jpg");
$tropo->say("Please enter your account number...",$params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"required":true,"promptLogSecurity":"suppress","media":"http://user:[email protected]/1.jpg"}]}]}');
}

public function testCreateSayObject5()
{
$tropo = new Tropo();
$allowSignals = array('exit','quit');
$params = array(
"as"=>SayAs::$date,
"event"=>"event",
"voice"=>Voice::$US_English_female_allison,
"allowSignals"=>$allowSignals,
"promptLogSecurity"=>"suppress",
"required"=>true,
"media"=>array('http://server.com/1.jpg', 'this is a inline text content', 'http://filehosting.tropo.com/account/1/2.text'));
$tropo->say("Please enter your account number...",$params);
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"required":true,"promptLogSecurity":"suppress","media":["http://server.com/1.jpg","this is a inline text content","http://filehosting.tropo.com/account/1/2.text"]}]}]}');
}

public function testFailsSayWithNoValueParameter1()
{
try{
Expand Down
14 changes: 13 additions & 1 deletion tests/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ class OnTest extends TestCase{

public function testCreateOnObject() {

$strSession = '{"session":{"id":"35b00c154f2fecacba37fad74e64a7e2","accountId":"1","applicationId":"1","timestamp":"2017-06-08T03:40:19.283Z","userType":"HUMAN","initialText":null,"callId":"c5b298fc0785fda9029f7f3b5aeef7ab","to":{"id":"9992801029","e164Id":"9992801029","name":"9992801029","channel":"VOICE","network":"SIP"},"from":{"id":"pengxli","e164Id":"pengxli","name":"pengxli","channel":"VOICE","network":"SIP"},"headers":{"Call-ID":"83369NTAxNDI2NDA4MWMzYTBiNzBiNmM0ZTVlMTQ4NjRlNmY","CSeq":"1 INVITE","Max-Forwards":"69","Request URI":"sip:[email protected];x-rt=0","Record-Route":"<sip:192.168.26.111:5060;transport=udp;lr>","x-sid":"6f1e3b7b2ace2a7785780b6337641388","User-Agent":"X-Lite release 4.9.7.1 stamp 83369","From":"<sip:[email protected]>;tag=1bb1ef33","Supported":"replaces","Allow":"SUBSCRIBE\\r\\nNOTIFY\\r\\nINVITE\\r\\nACK\\r\\nCANCEL\\r\\nBYE\\r\\nREFER\\r\\nINFO\\r\\nOPTIONS\\r\\nMESSAGE","Via":"SIP/2.0/UDP 192.168.26.111:5060;branch=z9hG4bK1vxcouwp4r78j;rport=5060\\r\\nSIP/2.0/UDP 192.168.26.1:5678;branch=z9hG4bK-524287-1---b1f649005b368755;rport=5678","Contact":"<sip:[email protected]:5678>","To":"<sip:[email protected]>","Content-Length":"335","Content-Type":"application/sdp"}}}';
$strSession = '{"session":{"id":"35b00c154f2fecacba37fad74e64a7e2","accountId":"1","applicationId":"1","timestamp":"2017-06-08T03:40:19.283Z","userType":"HUMAN","initialText":null,"subject": "Inbound MMS subject","initialMedia":[{"status":"success","media": "http://filehosting.tropo.com/account/1.jpg"},{"status":"success","text": "this is text"},{"status":"failure","disposition": "Failed to upload: 500 Internal Error","media": "2.jpg"}],"callId":"c5b298fc0785fda9029f7f3b5aeef7ab","to":{"id":"9992801029","e164Id":"9992801029","name":"9992801029","channel":"VOICE","network":"SIP"},"from":{"id":"pengxli","e164Id":"pengxli","name":"pengxli","channel":"VOICE","network":"SIP"},"headers":{"Call-ID":"83369NTAxNDI2NDA4MWMzYTBiNzBiNmM0ZTVlMTQ4NjRlNmY","CSeq":"1 INVITE","Max-Forwards":"69","Request URI":"sip:[email protected];x-rt=0","Record-Route":"<sip:192.168.26.111:5060;transport=udp;lr>","x-sid":"6f1e3b7b2ace2a7785780b6337641388","User-Agent":"X-Lite release 4.9.7.1 stamp 83369","From":"<sip:[email protected]>;tag=1bb1ef33","Supported":"replaces","Allow":"SUBSCRIBE\\r\\nNOTIFY\\r\\nINVITE\\r\\nACK\\r\\nCANCEL\\r\\nBYE\\r\\nREFER\\r\\nINFO\\r\\nOPTIONS\\r\\nMESSAGE","Via":"SIP/2.0/UDP 192.168.26.111:5060;branch=z9hG4bK1vxcouwp4r78j;rport=5060\\r\\nSIP/2.0/UDP 192.168.26.1:5678;branch=z9hG4bK-524287-1---b1f649005b368755;rport=5678","Contact":"<sip:[email protected]:5678>","To":"<sip:[email protected]>","Content-Length":"335","Content-Type":"application/sdp"}}}';
$session = new Session($strSession);
$this->assertEquals($session->getId(), '35b00c154f2fecacba37fad74e64a7e2');
$this->assertEquals($session->getAccountId(), '1');
$this->assertEquals($session->getTimestamp(), '2017-06-08T03:40:19.283Z');
$this->assertEquals($session->getUserType(), 'HUMAN');
$this->assertEquals($session->getInitialText(), null);
$initialMedia = $session->getInitialMedia();
$this->assertEquals($session->getStatusFromMedia($initialMedia[0]), "success");
$this->assertEquals($session->getMediaFromMedia($initialMedia[0]), "http://filehosting.tropo.com/account/1.jpg");

$this->assertEquals($session->getStatusFromMedia($initialMedia[1]), "success");
$this->assertEquals($session->getTextFromMedia($initialMedia[1]), "this is text");

$this->assertEquals($session->getStatusFromMedia($initialMedia[2]), "failure");
$this->assertEquals($session->getDispositionFromMedia($initialMedia[2]), "Failed to upload: 500 Internal Error");
$this->assertEquals($session->getMediaFromMedia($initialMedia[2]), "2.jpg");

$this->assertEquals($session->getSubject(), "Inbound MMS subject");
$this->assertEquals($session->getCallId(), 'c5b298fc0785fda9029f7f3b5aeef7ab');
$to = $session->getTo();
$this->assertEquals($to["id"], '9992801029');
Expand Down
44 changes: 41 additions & 3 deletions tropo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public function say($say, Array $params=NULL) {
if (isset($params)) {

if (is_array($params)) {
$p = array('as', 'event','voice', 'allowSignals', 'name', 'required', 'promptLogSecurity');
$p = array('as', 'event','voice', 'allowSignals', 'name', 'required', 'promptLogSecurity', 'media');
foreach ($p as $option) {
$$option = null;
if (array_key_exists($option, $params)) {
Expand All @@ -641,7 +641,7 @@ public function say($say, Array $params=NULL) {
}
$voice = isset($voice) ? $voice : $this->_voice;
$event = null;
$say = new Say($value, $as, $event, $voice, $allowSignals, $name, $required, $promptLogSecurity);
$say = new Say($value, $as, $event, $voice, $allowSignals, $name, $required, $promptLogSecurity, $media);
} else {
throw new Exception("When Argument 1 passed to Tropo::say() is a string, argument 2 passed to Tropo::say() must be of the type array.");
}
Expand Down Expand Up @@ -2233,6 +2233,7 @@ class Say extends BaseClass {
private $_name;
private $_required;
private $_promptLogSecurity;
private $_media;

public function getValue() {
return $this->_value;
Expand All @@ -2255,7 +2256,7 @@ public function setEvent($event) {
* @param string $voice
* @param string|array $allowSignals
*/
public function __construct($value, $as=NULL, $event=NULL, $voice=NULL, $allowSignals=NULL, $name=NULL, $required=NULL, $promptLogSecurity=NULL) {
public function __construct($value, $as=NULL, $event=NULL, $voice=NULL, $allowSignals=NULL, $name=NULL, $required=NULL, $promptLogSecurity=NULL, $media=NULL) {
if(!(is_string($value) && ($value != ''))) {
throw new Exception("Missing required property: 'value'");
}
Expand All @@ -2267,6 +2268,7 @@ public function __construct($value, $as=NULL, $event=NULL, $voice=NULL, $allowSi
$this->_name = $name;
$this->_required = $required;
$this->_promptLogSecurity = $promptLogSecurity;
$this->_media = $media;
}

/**
Expand All @@ -2282,6 +2284,7 @@ public function __toString() {
if(isset($this->_name)) { $this->name = $this->_name; }
if(isset($this->_required)) { $this->required = $this->_required; }
if(isset($this->_promptLogSecurity)) { $this->promptLogSecurity = $this->_promptLogSecurity; }
if(isset($this->_media)) { $this->media = $this->_media; }
return json_encode($this);
}
}
Expand All @@ -2305,6 +2308,8 @@ class Session {
private $_headers;
private $_parameters;
private $_userType;
private $_subject;
private $_initialMedia;

/**
* Class constructor
Expand All @@ -2330,6 +2335,14 @@ public function __construct($json=NULL) {
$this->_timestamp = $session->session->timestamp;
$this->_initialText = $session->session->initialText;
$this->_userType = $session->session->userType;
$this->_subject = isset($session->session->subject) ? $session->session->subject : null;
$this->_initialMedia = isset($session->session->initialMedia) ? $session->session->initialMedia : null;
if (is_object($this->_initialMedia)) {
$this->_text = isset($session->session->initialMedia->text) ? $session->session->initialMedia->text : null;
$this->_media = isset($session->session->initialMedia->media) ? $session->session->initialMedia->media : null;
$this->_status = isset($session->session->initialMedia->status) ? $session->session->initialMedia->status : null;
$this->_disposition = isset($session->session->initialMedia->disposition) ? $session->session->initialMedia->disposition : null;
}
$this->_to = isset($session->session->to)
? array(
"id" => $session->session->to->id,
Expand Down Expand Up @@ -2411,6 +2424,30 @@ public function getUserType() {
return $this->_userType;
}

public function getSubject() {
return $this->_subject;
}

public function getInitialMedia() {
return $this->_initialMedia;
}

public function getTextFromMedia($media) {
return isset($media->text) ? $media->text : null;
}

public function getMediaFromMedia($media) {
return isset($media->media) ? $media->media : null;
}

public function getStatusFromMedia($media) {
return isset($media->status) ? $media->status : null;
}

public function getDispositionFromMedia($media) {
return isset($media->disposition) ? $media->disposition : null;
}

/**
* Returns the query string parameters for the session api
*
Expand Down Expand Up @@ -2958,6 +2995,7 @@ class Network {
public static $yahoo = "YAHOO";
public static $twitter = "TWITTER";
public static $sip = "SIP";
public static $mms = "MMS";
}

/**
Expand Down

0 comments on commit 9144837

Please sign in to comment.