-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NEW] Twilio MMS support for LiveChat integration #7964
Changes from 5 commits
ee8563f
d3de53a
031aea0
7c24f73
a652384
eb0c4e8
dfe943b
8fb0c6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,30 @@ RocketChat.API.v1.addRoute('livechat/sms-incoming/:service', { | |
sendMessage.message.msg = sms.body; | ||
sendMessage.guest = visitor; | ||
|
||
if (sms.hasMedia) { | ||
sendMessage.message.attachments = []; | ||
for (let mediaIndex = 0; mediaIndex < sms.media.length; mediaIndex++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to use |
||
const attachment = {}; | ||
const contenttype = sms.media[mediaIndex].contenttype; | ||
|
||
switch (contenttype.substr(0, contenttype.indexOf('/'))) { | ||
case 'image': | ||
attachment.image_url = sms.media[mediaIndex].url; | ||
break; | ||
case 'video': | ||
attachment.video_url = sms.media[mediaIndex].url; | ||
break; | ||
case 'audio': | ||
attachment.audio_url = sms.media[mediaIndex].url; | ||
break; | ||
} | ||
|
||
attachment.message_link = sms.media[mediaIndex].url; | ||
|
||
sendMessage.message.attachments.push(attachment); | ||
} | ||
} | ||
|
||
try { | ||
const message = SMSService.response.call(this, RocketChat.Livechat.sendMessage(sendMessage)); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ class Twilio { | |
this.authToken = RocketChat.settings.get('SMS_Twilio_authToken'); | ||
} | ||
parse(data) { | ||
return { | ||
let NumMedia = 0; | ||
|
||
const returndata = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use camel case variables, i.e: |
||
from: data.From, | ||
to: data.To, | ||
body: data.Body, | ||
|
@@ -21,6 +23,35 @@ class Twilio { | |
fromZip: data.FromZip | ||
} | ||
}; | ||
|
||
if (data.NumMedia) { | ||
NumMedia = parseInt(data.NumMedia, 10); | ||
} | ||
|
||
if (isNaN(NumMedia)) { | ||
console.error(`Error parsing NumMedia ${ data.NumMedia }`); | ||
return returndata; | ||
} | ||
|
||
returndata.hasMedia = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are always setting |
||
returndata.media = []; | ||
|
||
for (let mediaIndex = 0; mediaIndex < NumMedia; mediaIndex++) { | ||
const media = { | ||
'url': '', | ||
'contenttype': '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use camel case properties, i.e: |
||
}; | ||
|
||
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) { | ||
const client = Npm.require('twilio')(this.accountSid, this.authToken); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will always enter on this
if
becausehasMedia
is alwaystrue
, so it is not really needed.