Skip to content

Commit

Permalink
TROPO-13425 add mms support
Browse files Browse the repository at this point in the history
  • Loading branch information
pengxli committed Aug 17, 2018
1 parent d93158b commit ced1f33
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
23 changes: 22 additions & 1 deletion lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ Result = function(json) {
return this;
};

Say = function(value, as, event, name, required, voice, allowSignals, promptLogSecurity) {
Say = function(value, as, event, name, required, voice, allowSignals, promptLogSecurity, media) {
if (value == null) {
throw new Error("Missing required property: 'value'");
}
Expand Down Expand Up @@ -1336,6 +1336,25 @@ Say = function(value, as, event, name, required, voice, allowSignals, promptLogS
throw new Error("Property: 'promptLogSecurity' must be a string");
}
}
if (media != null) {
if (Object.prototype.toString.call(media) === '[object String]') {
this.media = media;
} else if (Object.prototype.toString.call(media) === '[object Array]') {
if (media.length > 0) {
for (var i = 0; i < media.length; i++) {
if (Object.prototype.toString.call(media[i]) === '[object String]') {
} else {
throw new Error("Property: 'media' must be a string or an array of strings");
}
}
this.media = media;
} else {
throw new Error("Property: 'media' must be a string or an array of strings");
}
} else {
throw new Error("Property: 'media' must be a string or an array of strings");
}
}
return this;
}
};
Expand All @@ -1355,6 +1374,8 @@ Session = function(json) {
this.timestamp = session.timestamp;
this.to = session.to;
this.userType = session.userType;
this.subject = session.subject;
this.initialMedia = session.initialMedia;

return this;
};
Expand Down
4 changes: 2 additions & 2 deletions lib/tropo-webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ TropoWebAPI.prototype.reject = function() {
this.tropo.push({"reject": reject});
};

TropoWebAPI.prototype.say = function(value, as, event, name, required, voice, allowSignals, promptLogSecurity) {
var say = new base.Say(value, as, event, name, required, voice, allowSignals, promptLogSecurity);
TropoWebAPI.prototype.say = function(value, as, event, name, required, voice, allowSignals, promptLogSecurity, media) {
var say = new base.Say(value, as, event, name, required, voice, allowSignals, promptLogSecurity, media);
this.tropo.push({"say": say});
};

Expand Down
42 changes: 42 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ var assert = require('assert');
var util = require('util');

var sayExpected = '{"tropo":[{"say":{"value":"Hello, World.","required":true,"voice":"carmen"}}]}';
var say1Expected = '{"tropo":[{"say":{"value":"Hello, World.","required":true,"voice":"carmen","media":"http://user:[email protected]/1.jpg"}}]}';
var say2Expected = '{"tropo":[{"say":{"value":"Hello, World.","required":true,"voice":"carmen","media":["http://server.com/1.jpg","this is a inline text content","http://filehosting.tropo.com/account/1/2.text"]}}]}';
var askExpected = '{"tropo":[{"ask":{"choices":{"value":"[5 DIGITS]"},"say":{"value":"Please say your account number."},"bargein":true,"required":true,"timeout":30}}]}';
var callExpected = '{"tropo":[{"call":{"to":"3055195825"}}]}';
var conferenceExpected = '{"tropo":[{"conference":{"id":"1234","mute":false,"playTones":false,"terminator":"#"}}]}';
var hangupExpected = '{"tropo":[{"hangup":{}}]}';
var messageExpected = '{"tropo":[{"message":{"say":{"value":"This is an announcement"},"to":"3055195825","answerOnMedia":false,"channel":"TEXT","from":"3055551212","network":"SMS","timeout":10,"voice":"kate"}}]}';
var message1Expected = '{"tropo":[{"message":{"say":{"value":"This is an announcement","media":"http://user:[email protected]/1.jpg"},"to":"3055195825","answerOnMedia":false,"channel":"TEXT","from":"3055551212","network":"MMS","timeout":10,"voice":"kate"}}]}';
var message2Expected = '{"tropo":[{"message":{"say":{"value":"This is an announcement","media":["http://server.com/1.jpg","this is a inline text content","http://filehosting.tropo.com/account/1/2.text"]},"to":"3055195825","answerOnMedia":false,"channel":"TEXT","from":"3055551212","network":"MMS","timeout":10,"voice":"kate"}}]}';
var recordExpected = '{"tropo":[{"record":{"beep":true,"choices":{"terminator":"#"},"maxSilence":5,"method":"POST","required":true,"say":{"value":"Please say your account number"}}}]}';

var numTests = 0;
Expand All @@ -22,11 +26,15 @@ var numFailed = 0;
console.log('***** Starting Test Run ************');
console.log(' ');
console.log('Say Test: ' + sayTest(sayExpected));
console.log('Say Test1: ' + say1Test(say1Expected));
console.log('Say Test2: ' + say2Test(say2Expected));
console.log('Ask Test: ' + askTest(askExpected));
console.log('Call Test: ' + callTest(callExpected));
console.log('Conference Test: ' + conferenceTest(conferenceExpected));
console.log('Hangup Test: ' + hangupTest(hangupExpected));
console.log('Message Test: ' + messageTest(messageExpected));
console.log('Message Test1: ' + message1Test(message1Expected));
console.log('Message Test2: ' + message2Test(message2Expected));
console.log('Record Test: ' + recordTest(recordExpected));
console.log('');
console.log('Total Tests Run: ' + numTests);
Expand All @@ -43,6 +51,22 @@ function sayTest(expected) {

}

function say1Test(expected) {

var tropo = new TropoWebAPI();
tropo.say("Hello, World.", null, null, null, true, "carmen", null, null, "http://user:[email protected]/1.jpg");
return runTest(TropoJSON(tropo), expected);

}

function say2Test(expected) {

var tropo = new TropoWebAPI();
tropo.say("Hello, World.", null, null, null, true, "carmen", null, null, new Array("http://server.com/1.jpg","this is a inline text content","http://filehosting.tropo.com/account/1/2.text"));
return runTest(TropoJSON(tropo), expected);

}

// A test for the Tropo Ask object.
function askTest(expected) {

Expand Down Expand Up @@ -87,6 +111,24 @@ function messageTest(expected) {

}

function message1Test(expected) {

var tropo = new TropoWebAPI();
var say = new Say("This is an announcement", null, null, null, null, null, null, null, "http://user:[email protected]/1.jpg");
tropo.message(say, "3055195825", false, "TEXT", "3055551212", null, "MMS", null, 10, "kate");
return runTest(TropoJSON(tropo), expected);

}

function message2Test(expected) {

var tropo = new TropoWebAPI();
var say = new Say("This is an announcement", null, null, null, null, null, null, null, new Array("http://server.com/1.jpg","this is a inline text content","http://filehosting.tropo.com/account/1/2.text"));
tropo.message(say, "3055195825", false, "TEXT", "3055551212", null, "MMS", null, 10, "kate");
return runTest(TropoJSON(tropo), expected);

}

// A test for the Tropo Record object.
function recordTest(expected) {

Expand Down

0 comments on commit ced1f33

Please sign in to comment.