Skip to content
Snippets Groups Projects
Commit 2c856c0b authored by t3hchipmunk's avatar t3hchipmunk Committed by Rodrigo Nascimento
Browse files

[NEW] Twilio MMS support for LiveChat integration (#7964)

* Added ability for MMS messaging to push through attachments

* Fixed issues for codacy https://www.codacy.com/app/RocketChat/Rocket-Chat/pullRequest?prid=875706

* Fixed more codacy issues

* Changes concerning feedback from dev

* Switch to camelcase
* Changed hasMedia (removed)
* use map instead of for loop for populating attachments

* Save map return on message attachments
parent 3115ec60
No related branches found
No related tags found
No related merge requests found
...@@ -46,6 +46,27 @@ RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { ...@@ -46,6 +46,27 @@ RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', {
sendMessage.message.msg = sms.body; sendMessage.message.msg = sms.body;
sendMessage.guest = visitor; sendMessage.guest = visitor;
sendMessage.message.attachments = sms.media.map(curr => {
const attachment = {
message_link: curr.url
};
const contentType = curr.contentType;
switch (contentType.substr(0, contentType.indexOf('/'))) {
case 'image':
attachment.image_url = curr.url;
break;
case 'video':
attachment.video_url = curr.url;
break;
case 'audio':
attachment.audio_url = curr.url;
break;
}
return attachment;
});
try { try {
const message = SMSService.response.call(this, RocketChat.Livechat.sendMessage(sendMessage)); const message = SMSService.response.call(this, RocketChat.Livechat.sendMessage(sendMessage));
......
...@@ -7,7 +7,9 @@ class Twilio { ...@@ -7,7 +7,9 @@ class Twilio {
this.authToken = RocketChat.settings.get('SMS_Twilio_authToken'); this.authToken = RocketChat.settings.get('SMS_Twilio_authToken');
} }
parse(data) { parse(data) {
return { let numMedia = 0;
const returnData = {
from: data.From, from: data.From,
to: data.To, to: data.To,
body: data.Body, body: data.Body,
...@@ -23,6 +25,34 @@ class Twilio { ...@@ -23,6 +25,34 @@ class Twilio {
fromZip: data.FromZip fromZip: data.FromZip
} }
}; };
if (data.NumMedia) {
numMedia = parseInt(data.NumMedia, 10);
}
if (isNaN(numMedia)) {
console.error(`Error parsing NumMedia ${ data.NumMedia }`);
return returnData;
}
returnData.media = [];
for (let mediaIndex = 0; mediaIndex < numMedia; mediaIndex++) {
const media = {
'url': '',
'contentType': ''
};
const mediaUrl = data[`MediaUrl${ mediaIndex }`];
const contentType = data[`MediaContentType${ mediaIndex }`];
media.url = mediaUrl;
media.contentType = contentType;
returnData.media.push(media);
}
return returnData;
} }
send(fromNumber, toNumber, message) { send(fromNumber, toNumber, message) {
const client = twilio(this.accountSid, this.authToken); const client = twilio(this.accountSid, this.authToken);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment