Added MMS support for messaging. IO-538
This commit is contained in:
@@ -29,11 +29,13 @@ exports.receive = (req, res) => {
|
||||
phone: phone(req.body.From)[0],
|
||||
})
|
||||
.then((response) => {
|
||||
console.log("re", req.body);
|
||||
|
||||
let newMessage = {
|
||||
msid: req.body.SmsMessageSid,
|
||||
text: req.body.Body,
|
||||
image: !!req.body.MediaUrl0,
|
||||
image_path: req.body.MediaUrl0 || null,
|
||||
image_path: generateMediaArray(req.body),
|
||||
};
|
||||
if (response.bodyshops[0]) {
|
||||
//Found a bodyshop - should always happen.
|
||||
@@ -164,3 +166,17 @@ exports.receive = (req, res) => {
|
||||
|
||||
// [0] MediaContentType0: 'image/jpeg',
|
||||
// MediaContentType0: 'video/3gpp',
|
||||
|
||||
const generateMediaArray = (body) => {
|
||||
const { NumMedia } = body;
|
||||
if (parseInt(NumMedia) > 0) {
|
||||
//stuff
|
||||
const ret = [];
|
||||
for (var i = 0; i < parseInt(NumMedia); i++) {
|
||||
ret.push(body[`MediaUrl${i}`]);
|
||||
}
|
||||
return ret;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,7 +17,13 @@ const client = twilio(
|
||||
const gqlClient = require("../graphql-client/graphql-client").client;
|
||||
|
||||
exports.send = (req, res) => {
|
||||
const { to, messagingServiceSid, body, conversationid } = req.body;
|
||||
const {
|
||||
to,
|
||||
messagingServiceSid,
|
||||
body,
|
||||
conversationid,
|
||||
selectedMedia,
|
||||
} = req.body;
|
||||
console.log("[Sending Sms] " + conversationid + " | " + body);
|
||||
if (!!to && !!messagingServiceSid && !!body && !!conversationid) {
|
||||
client.messages
|
||||
@@ -25,6 +31,7 @@ exports.send = (req, res) => {
|
||||
body: body,
|
||||
messagingServiceSid: messagingServiceSid,
|
||||
to: phone(to)[0],
|
||||
mediaUrl: selectedMedia.map((i) => i.src),
|
||||
})
|
||||
.then((message) => {
|
||||
let newMessage = {
|
||||
@@ -33,6 +40,11 @@ exports.send = (req, res) => {
|
||||
conversationid,
|
||||
isoutbound: true,
|
||||
userid: req.user.email,
|
||||
image: req.body.selectedMedia.length > 0,
|
||||
image_path:
|
||||
req.body.selectedMedia.length > 0
|
||||
? selectedMedia.map((i) => i.src)
|
||||
: [],
|
||||
};
|
||||
gqlClient
|
||||
.request(queries.INSERT_MESSAGE, { msg: newMessage })
|
||||
@@ -55,3 +67,23 @@ exports.send = (req, res) => {
|
||||
.json({ success: false, message: "Missing required parameter(s)." });
|
||||
}
|
||||
};
|
||||
|
||||
// //Image
|
||||
// acc.push({
|
||||
// src: `${process.env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
||||
// value.type
|
||||
// )}/upload/${value.key}`,
|
||||
// thumbnail: `${
|
||||
// process.env.REACT_APP_CLOUDINARY_ENDPOINT
|
||||
// }/${DetermineFileType(value.type)}/upload/${
|
||||
// process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS
|
||||
// }/${value.key}`,
|
||||
// thumbnailHeight: 225,
|
||||
// thumbnailWidth: 225,
|
||||
// isSelected: false,
|
||||
// key: value.key,
|
||||
// extension: value.extension,
|
||||
// id: value.id,
|
||||
// type: value.type,
|
||||
// tags: [{ value: value.type, title: value.type }],
|
||||
// });
|
||||
|
||||
Reference in New Issue
Block a user