Skip to content

Commit 9144837

Browse files
committed
TROPO-13424 add MMS support
1 parent af88e52 commit 9144837

File tree

4 files changed

+132
-4
lines changed

4 files changed

+132
-4
lines changed

tests/MessageTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ public function testMessageWithMinOptions() {
1414
$this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":{"value":"This is an announcement."},"to":"sip:[email protected]:5678"}}]}');
1515
}
1616

17+
public function testMessageWithMMS() {
18+
$tropo = new Tropo();
19+
$say = new Say("This is the subject",null, null, null, null, null,null,null,"http://user:[email protected]/1.jpg");
20+
$message = new Message($say,'sip:[email protected]:5678',null, Network::$mms);
21+
$tropo->message($message);
22+
$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"}}]}');
23+
}
24+
25+
public function testMessageWithMMS1() {
26+
$tropo = new Tropo();
27+
$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"));
28+
$message = new Message($say,'sip:[email protected]:5678',null, Network::$mms);
29+
$tropo->message($message);
30+
$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"}}]}');
31+
}
32+
1733
public function testMessageWithExtraSayOptiions() {
1834
$tropo = new Tropo();
1935
$say = "Remember, you have a meeting at 2 PM.";

tests/SayTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ public function testSayWithOptions() {
1616
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","name":"say"}]}]}');
1717
}
1818

19+
public function testSayWithOptions1() {
20+
$tropo = new Tropo();
21+
$tropo->say("Please enter your account number...",array('name' => 'say','media' => 'http://user:[email protected]/1.jpg'));
22+
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","name":"say","media":"http://user:[email protected]/1.jpg"}]}]}');
23+
}
24+
25+
public function testSayWithOptions2() {
26+
$tropo = new Tropo();
27+
$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')));
28+
$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"]}]}]}');
29+
}
30+
1931
public function testCreateSayObject()
2032
{
2133
$tropo = new Tropo();
@@ -40,6 +52,56 @@ public function testCreateSayObject1()
4052
$this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"required":true,"promptLogSecurity":"suppress"}]}]}');
4153
}
4254

55+
public function testCreateSayObject2()
56+
{
57+
$tropo = new Tropo();
58+
$allowSignals = array('exit','quit');
59+
$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");
60+
$tropo->say($say);
61+
$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"}]}]}');
62+
}
63+
64+
public function testCreateSayObject3()
65+
{
66+
$tropo = new Tropo();
67+
$allowSignals = array('exit','quit');
68+
$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'));
69+
$tropo->say($say);
70+
$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"]}]}]}');
71+
}
72+
73+
public function testCreateSayObject4()
74+
{
75+
$tropo = new Tropo();
76+
$allowSignals = array('exit','quit');
77+
$params = array(
78+
"as"=>SayAs::$date,
79+
"event"=>"event",
80+
"voice"=>Voice::$US_English_female_allison,
81+
"allowSignals"=>$allowSignals,
82+
"promptLogSecurity"=>"suppress",
83+
"required"=>true,
84+
"media"=>"http://user:[email protected]/1.jpg");
85+
$tropo->say("Please enter your account number...",$params);
86+
$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"}]}]}');
87+
}
88+
89+
public function testCreateSayObject5()
90+
{
91+
$tropo = new Tropo();
92+
$allowSignals = array('exit','quit');
93+
$params = array(
94+
"as"=>SayAs::$date,
95+
"event"=>"event",
96+
"voice"=>Voice::$US_English_female_allison,
97+
"allowSignals"=>$allowSignals,
98+
"promptLogSecurity"=>"suppress",
99+
"required"=>true,
100+
"media"=>array('http://server.com/1.jpg', 'this is a inline text content', 'http://filehosting.tropo.com/account/1/2.text'));
101+
$tropo->say("Please enter your account number...",$params);
102+
$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"]}]}]}');
103+
}
104+
43105
public function testFailsSayWithNoValueParameter1()
44106
{
45107
try{

tests/SessionTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ class OnTest extends TestCase{
66

77
public function testCreateOnObject() {
88

9-
$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"}}}';
9+
$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"}}}';
1010
$session = new Session($strSession);
1111
$this->assertEquals($session->getId(), '35b00c154f2fecacba37fad74e64a7e2');
1212
$this->assertEquals($session->getAccountId(), '1');
1313
$this->assertEquals($session->getTimestamp(), '2017-06-08T03:40:19.283Z');
1414
$this->assertEquals($session->getUserType(), 'HUMAN');
1515
$this->assertEquals($session->getInitialText(), null);
16+
$initialMedia = $session->getInitialMedia();
17+
$this->assertEquals($session->getStatusFromMedia($initialMedia[0]), "success");
18+
$this->assertEquals($session->getMediaFromMedia($initialMedia[0]), "http://filehosting.tropo.com/account/1.jpg");
19+
20+
$this->assertEquals($session->getStatusFromMedia($initialMedia[1]), "success");
21+
$this->assertEquals($session->getTextFromMedia($initialMedia[1]), "this is text");
22+
23+
$this->assertEquals($session->getStatusFromMedia($initialMedia[2]), "failure");
24+
$this->assertEquals($session->getDispositionFromMedia($initialMedia[2]), "Failed to upload: 500 Internal Error");
25+
$this->assertEquals($session->getMediaFromMedia($initialMedia[2]), "2.jpg");
26+
27+
$this->assertEquals($session->getSubject(), "Inbound MMS subject");
1628
$this->assertEquals($session->getCallId(), 'c5b298fc0785fda9029f7f3b5aeef7ab');
1729
$to = $session->getTo();
1830
$this->assertEquals($to["id"], '9992801029');

tropo.class.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ public function say($say, Array $params=NULL) {
632632
if (isset($params)) {
633633

634634
if (is_array($params)) {
635-
$p = array('as', 'event','voice', 'allowSignals', 'name', 'required', 'promptLogSecurity');
635+
$p = array('as', 'event','voice', 'allowSignals', 'name', 'required', 'promptLogSecurity', 'media');
636636
foreach ($p as $option) {
637637
$$option = null;
638638
if (array_key_exists($option, $params)) {
@@ -641,7 +641,7 @@ public function say($say, Array $params=NULL) {
641641
}
642642
$voice = isset($voice) ? $voice : $this->_voice;
643643
$event = null;
644-
$say = new Say($value, $as, $event, $voice, $allowSignals, $name, $required, $promptLogSecurity);
644+
$say = new Say($value, $as, $event, $voice, $allowSignals, $name, $required, $promptLogSecurity, $media);
645645
} else {
646646
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.");
647647
}
@@ -2233,6 +2233,7 @@ class Say extends BaseClass {
22332233
private $_name;
22342234
private $_required;
22352235
private $_promptLogSecurity;
2236+
private $_media;
22362237

22372238
public function getValue() {
22382239
return $this->_value;
@@ -2255,7 +2256,7 @@ public function setEvent($event) {
22552256
* @param string $voice
22562257
* @param string|array $allowSignals
22572258
*/
2258-
public function __construct($value, $as=NULL, $event=NULL, $voice=NULL, $allowSignals=NULL, $name=NULL, $required=NULL, $promptLogSecurity=NULL) {
2259+
public function __construct($value, $as=NULL, $event=NULL, $voice=NULL, $allowSignals=NULL, $name=NULL, $required=NULL, $promptLogSecurity=NULL, $media=NULL) {
22592260
if(!(is_string($value) && ($value != ''))) {
22602261
throw new Exception("Missing required property: 'value'");
22612262
}
@@ -2267,6 +2268,7 @@ public function __construct($value, $as=NULL, $event=NULL, $voice=NULL, $allowSi
22672268
$this->_name = $name;
22682269
$this->_required = $required;
22692270
$this->_promptLogSecurity = $promptLogSecurity;
2271+
$this->_media = $media;
22702272
}
22712273

22722274
/**
@@ -2282,6 +2284,7 @@ public function __toString() {
22822284
if(isset($this->_name)) { $this->name = $this->_name; }
22832285
if(isset($this->_required)) { $this->required = $this->_required; }
22842286
if(isset($this->_promptLogSecurity)) { $this->promptLogSecurity = $this->_promptLogSecurity; }
2287+
if(isset($this->_media)) { $this->media = $this->_media; }
22852288
return json_encode($this);
22862289
}
22872290
}
@@ -2305,6 +2308,8 @@ class Session {
23052308
private $_headers;
23062309
private $_parameters;
23072310
private $_userType;
2311+
private $_subject;
2312+
private $_initialMedia;
23082313

23092314
/**
23102315
* Class constructor
@@ -2330,6 +2335,14 @@ public function __construct($json=NULL) {
23302335
$this->_timestamp = $session->session->timestamp;
23312336
$this->_initialText = $session->session->initialText;
23322337
$this->_userType = $session->session->userType;
2338+
$this->_subject = isset($session->session->subject) ? $session->session->subject : null;
2339+
$this->_initialMedia = isset($session->session->initialMedia) ? $session->session->initialMedia : null;
2340+
if (is_object($this->_initialMedia)) {
2341+
$this->_text = isset($session->session->initialMedia->text) ? $session->session->initialMedia->text : null;
2342+
$this->_media = isset($session->session->initialMedia->media) ? $session->session->initialMedia->media : null;
2343+
$this->_status = isset($session->session->initialMedia->status) ? $session->session->initialMedia->status : null;
2344+
$this->_disposition = isset($session->session->initialMedia->disposition) ? $session->session->initialMedia->disposition : null;
2345+
}
23332346
$this->_to = isset($session->session->to)
23342347
? array(
23352348
"id" => $session->session->to->id,
@@ -2411,6 +2424,30 @@ public function getUserType() {
24112424
return $this->_userType;
24122425
}
24132426

2427+
public function getSubject() {
2428+
return $this->_subject;
2429+
}
2430+
2431+
public function getInitialMedia() {
2432+
return $this->_initialMedia;
2433+
}
2434+
2435+
public function getTextFromMedia($media) {
2436+
return isset($media->text) ? $media->text : null;
2437+
}
2438+
2439+
public function getMediaFromMedia($media) {
2440+
return isset($media->media) ? $media->media : null;
2441+
}
2442+
2443+
public function getStatusFromMedia($media) {
2444+
return isset($media->status) ? $media->status : null;
2445+
}
2446+
2447+
public function getDispositionFromMedia($media) {
2448+
return isset($media->disposition) ? $media->disposition : null;
2449+
}
2450+
24142451
/**
24152452
* Returns the query string parameters for the session api
24162453
*
@@ -2958,6 +2995,7 @@ class Network {
29582995
public static $yahoo = "YAHOO";
29592996
public static $twitter = "TWITTER";
29602997
public static $sip = "SIP";
2998+
public static $mms = "MMS";
29612999
}
29623000

29633001
/**

0 commit comments

Comments
 (0)