diff --git a/README.MD b/README.MD index 1b160524b..ee13fca5e 100644 --- a/README.MD +++ b/README.MD @@ -16,7 +16,7 @@ npx hasura migrate apply --endpoint https://db.imex.online/ --admin-secret 'Prod NGROK TEsting: -./ngrok.exe http https://localhost:5000 -host-header="localhost:5000" +./ngrok.exe http http://localhost:5000 -host-header="localhost:5000" Finding deadfiles - run from client directory npx deadfile ./src/index.js --exclude build templates diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index ed5de8f3c..2d4bddd55 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -21831,6 +21831,27 @@ labels + + maxtenimages + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + messaging false @@ -21936,6 +21957,27 @@ + + selectmedia + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + sentby false diff --git a/client/src/components/chat-media-selector/chat-media-selector.component.jsx b/client/src/components/chat-media-selector/chat-media-selector.component.jsx new file mode 100644 index 000000000..c2734403f --- /dev/null +++ b/client/src/components/chat-media-selector/chat-media-selector.component.jsx @@ -0,0 +1,88 @@ +import { PictureFilled } from "@ant-design/icons"; +import { useQuery } from "@apollo/react-hooks"; +import { Badge, Popover } from "antd"; +import React, { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; +import { GET_DOCUMENTS_BY_JOB } from "../../graphql/documents.queries"; +import AlertComponent from "../alert/alert.component"; +import JobDocumentsGalleryExternal from "../jobs-documents-gallery/jobs-documents-gallery.external.component"; +import LoadingSpinner from "../loading-spinner/loading-spinner.component"; + +const mapStateToProps = createStructuredSelector({ + //currentUser: selectCurrentUser +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); +export default connect(mapStateToProps, mapDispatchToProps)(ChatMediaSelector); + +export function ChatMediaSelector({ + selectedMedia, + setSelectedMedia, + conversation, +}) { + const { t } = useTranslation(); + console.log("conversation", conversation); + const { loading, error, data, refetch } = useQuery(GET_DOCUMENTS_BY_JOB, { + variables: { + jobId: + conversation.job_conversations[0] && + conversation.job_conversations[0].jobid, + }, + fetchPolicy: "network-only", + skip: + !conversation.job_conversations || + conversation.job_conversations.length === 0, + }); + + const [visible, setVisible] = useState(false); + + const handleVisibleChange = (visible) => { + setVisible(visible); + }; + + useEffect(() => { + setSelectedMedia([]); + }, [setSelectedMedia, conversation]); + + const content = ( +
+ {loading && } + {error && } + {selectedMedia.filter((s) => s.isSelected).length >= 10 ? ( +
{t("messaging.labels.maxtenimages")}
+ ) : null} + {data && ( + + )} +
+ ); + + return ( + {t("messaging.errors.noattachedjobs")} + ) : ( + content + ) + } + title={t("messaging.labels.selectmedia")} + trigger="click" + visible={visible} + onVisibleChange={handleVisibleChange} + > + s.isSelected).length} + > + + + + ); +} diff --git a/client/src/components/chat-messages-list/chat-message-list.component.jsx b/client/src/components/chat-messages-list/chat-message-list.component.jsx index c4a55b157..2780f5441 100644 --- a/client/src/components/chat-messages-list/chat-message-list.component.jsx +++ b/client/src/components/chat-messages-list/chat-message-list.component.jsx @@ -1,4 +1,6 @@ import Icon from "@ant-design/icons"; +import i18n from "i18next"; +import moment from "moment"; import React, { useEffect, useRef } from "react"; import { MdDone, MdDoneAll } from "react-icons/md"; import { @@ -8,8 +10,6 @@ import { List, } from "react-virtualized"; import "./chat-message-list.styles.scss"; -import i18n from "i18next"; -import moment from "moment"; export default function ChatMessageListComponent({ messages }) { const virtualizedListRef = useRef(null); @@ -46,6 +46,16 @@ export default function ChatMessageListComponent({ messages }) { {MessageRender(messages[index])} {StatusRender(messages[index].status)} + {messages[index].isoutbound && ( +
+ {i18n.t("messaging.labels.sentby", { + by: messages[index].userid, + time: moment(messages[index].created_at).format( + "MM/DD/YYYY @ hh:mm a" + ), + })} +
+ )} )} @@ -74,27 +84,19 @@ export default function ChatMessageListComponent({ messages }) { } const MessageRender = (message) => { - if (message.image) { - return ( - - Received - - ); - } else { - return ( -
-
{message.text}
- {message.isoutbound && ( -
- {i18n.t("messaging.labels.sentby", { - by: message.userid, - time: moment(message.created_at).format("MM/DD/YYYY @ hh:mm a"), - })} + return ( +
+ {message.image_path && + message.image_path.map((i, idx) => ( + - )} -
- ); - } + ))} +
{message.text}
+
+ ); }; const StatusRender = (status) => { diff --git a/client/src/components/chat-messages-list/chat-message-list.styles.scss b/client/src/components/chat-messages-list/chat-message-list.styles.scss index f945a5556..19cfe1451 100644 --- a/client/src/components/chat-messages-list/chat-message-list.styles.scss +++ b/client/src/components/chat-messages-list/chat-message-list.styles.scss @@ -34,9 +34,10 @@ //display: inline-block; .message-img { - max-width: 3rem; - max-height: 3rem; + max-width: 10rem; + max-height: 10rem; object-fit: contain; + margin: 0.2rem; } } diff --git a/client/src/components/chat-send-message/chat-send-message.component.jsx b/client/src/components/chat-send-message/chat-send-message.component.jsx index 75af41e4a..33b5656fa 100644 --- a/client/src/components/chat-send-message/chat-send-message.component.jsx +++ b/client/src/components/chat-send-message/chat-send-message.component.jsx @@ -1,6 +1,6 @@ import { LoadingOutlined, SendOutlined } from "@ant-design/icons"; import { Input, Spin } from "antd"; -import React, { useEffect, useRef } from "react"; +import React, { useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; @@ -14,6 +14,7 @@ import { selectMessage, } from "../../redux/messaging/messaging.selectors"; import { selectBodyshop } from "../../redux/user/user.selectors"; +import ChatMediaSelector from "../chat-media-selector/chat-media-selector.component"; import ChatPresetsComponent from "../chat-presets/chat-presets.component"; const mapStateToProps = createStructuredSelector({ @@ -36,6 +37,7 @@ function ChatSendMessageComponent({ setMessage, }) { const inputArea = useRef(null); + const [selectedMedia, setSelectedMedia] = useState([]); useEffect(() => { inputArea.current.focus(); }, [isSending, setMessage]); @@ -43,36 +45,55 @@ function ChatSendMessageComponent({ const { t } = useTranslation(); const handleEnter = () => { + if (message === "" || !message) return; logImEXEvent("messaging_send_message"); - sendMessage({ - to: conversation.phone_num, - body: message, - messagingServiceSid: bodyshop.messagingservicesid, - conversationid: conversation.id, - }); + const selectedImages = selectedMedia.filter((i) => i.isSelected); + if (selectedImages < 11) { + sendMessage({ + to: conversation.phone_num, + body: message, + messagingServiceSid: bodyshop.messagingservicesid, + conversationid: conversation.id, + selectedMedia: selectedImages, + }); + setSelectedMedia( + selectedMedia.map((i) => { + return { ...i, isSelected: false }; + }) + ); + } }; return (
- - setMessage(e.target.value)} - onPressEnter={(event) => { - event.preventDefault(); - if (!!!event.shiftKey) handleEnter(); - }} + + + setMessage(e.target.value)} + onPressEnter={(event) => { + event.preventDefault(); + if (!!!event.shiftKey) handleEnter(); + }} + /> + + - - { + let documents = data.reduce((acc, value) => { + if (value.type.startsWith("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 }], + }); + } + + return acc; + }, []); + setgalleryImages(documents); + }, [data, setgalleryImages, t]); + + return ( +
+ { + setgalleryImages( + galleryImages.map((g, idx) => + index === idx ? { ...g, isSelected: !g.isSelected } : g + ) + ); + }} + /> +
+ ); +} +export default JobsDocumentGalleryExternal; diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 119f0f28e..6d1f0db04 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -1310,11 +1310,13 @@ "new": "New Conversation" }, "labels": { + "maxtenimages": "You can only select up to a maximum of 10 images at a time.", "messaging": "Messaging", "noallowtxt": "This customer has not indicated their permission to be messaged.", "nojobs": "Not associated to any job.", "phonenumber": "Phone #", "presets": "Presets", + "selectmedia": "Select Media", "sentby": "Sent by {{by}} at {{time}}", "typeamessage": "Send a message..." } diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index b3cf88469..bc8d7de74 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -1310,11 +1310,13 @@ "new": "" }, "labels": { + "maxtenimages": "", "messaging": "Mensajería", "noallowtxt": "", "nojobs": "", "phonenumber": "", "presets": "", + "selectmedia": "", "sentby": "", "typeamessage": "Enviar un mensaje..." } diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 1e0823a82..0a4b0a03b 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -1310,11 +1310,13 @@ "new": "" }, "labels": { + "maxtenimages": "", "messaging": "Messagerie", "noallowtxt": "", "nojobs": "", "phonenumber": "", "presets": "", + "selectmedia": "", "sentby": "", "typeamessage": "Envoyer un message..." } diff --git a/hasura/migrations/1613767928898_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1613767928898_update_permission_user_public_table_messages/down.yaml new file mode 100644 index 000000000..81a526283 --- /dev/null +++ b/hasura/migrations/1613767928898_update_permission_user_public_table_messages/down.yaml @@ -0,0 +1,37 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_insert_permission +- args: + permission: + check: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - conversationid + - created_at + - id + - image + - image_path + - isoutbound + - msid + - read + - status + - text + - updated_at + - userid + set: {} + role: user + table: + name: messages + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1613767928898_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1613767928898_update_permission_user_public_table_messages/up.yaml new file mode 100644 index 000000000..043c11b36 --- /dev/null +++ b/hasura/migrations/1613767928898_update_permission_user_public_table_messages/up.yaml @@ -0,0 +1,36 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_insert_permission +- args: + permission: + check: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - conversationid + - created_at + - id + - image + - isoutbound + - msid + - read + - status + - text + - updated_at + - userid + set: {} + role: user + table: + name: messages + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1613767944643_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1613767944643_update_permission_user_public_table_messages/down.yaml new file mode 100644 index 000000000..e0238e6f8 --- /dev/null +++ b/hasura/migrations/1613767944643_update_permission_user_public_table_messages/down.yaml @@ -0,0 +1,38 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: true + columns: + - conversationid + - created_at + - id + - image + - image_path + - isoutbound + - msid + - read + - status + - text + - updated_at + - userid + computed_fields: [] + filter: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: messages + schema: public + type: create_select_permission diff --git a/hasura/migrations/1613767944643_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1613767944643_update_permission_user_public_table_messages/up.yaml new file mode 100644 index 000000000..ae24478b6 --- /dev/null +++ b/hasura/migrations/1613767944643_update_permission_user_public_table_messages/up.yaml @@ -0,0 +1,37 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: true + columns: + - conversationid + - created_at + - id + - image + - isoutbound + - msid + - read + - status + - text + - updated_at + - userid + computed_fields: [] + filter: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: messages + schema: public + type: create_select_permission diff --git a/hasura/migrations/1613767953059_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1613767953059_update_permission_user_public_table_messages/down.yaml new file mode 100644 index 000000000..35bc9ab52 --- /dev/null +++ b/hasura/migrations/1613767953059_update_permission_user_public_table_messages/down.yaml @@ -0,0 +1,36 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_update_permission +- args: + permission: + columns: + - image + - isoutbound + - read + - image_path + - msid + - status + - text + - created_at + - updated_at + - conversationid + - id + filter: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: messages + schema: public + type: create_update_permission diff --git a/hasura/migrations/1613767953059_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1613767953059_update_permission_user_public_table_messages/up.yaml new file mode 100644 index 000000000..2cde6b1c2 --- /dev/null +++ b/hasura/migrations/1613767953059_update_permission_user_public_table_messages/up.yaml @@ -0,0 +1,35 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_update_permission +- args: + permission: + columns: + - conversationid + - created_at + - id + - image + - isoutbound + - msid + - read + - status + - text + - updated_at + filter: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: messages + schema: public + type: create_update_permission diff --git a/hasura/migrations/1613767963376_alter_table_public_messages_drop_column_image_path/down.yaml b/hasura/migrations/1613767963376_alter_table_public_messages_drop_column_image_path/down.yaml new file mode 100644 index 000000000..155db26b8 --- /dev/null +++ b/hasura/migrations/1613767963376_alter_table_public_messages_drop_column_image_path/down.yaml @@ -0,0 +1,10 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."messages" ADD COLUMN "image_path" text; + type: run_sql +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."messages" ALTER COLUMN "image_path" DROP NOT NULL; + type: run_sql diff --git a/hasura/migrations/1613767963376_alter_table_public_messages_drop_column_image_path/up.yaml b/hasura/migrations/1613767963376_alter_table_public_messages_drop_column_image_path/up.yaml new file mode 100644 index 000000000..67f6e217d --- /dev/null +++ b/hasura/migrations/1613767963376_alter_table_public_messages_drop_column_image_path/up.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."messages" DROP COLUMN "image_path" CASCADE; + type: run_sql diff --git a/hasura/migrations/1613767994173_alter_table_public_messages_add_column_image_path/down.yaml b/hasura/migrations/1613767994173_alter_table_public_messages_add_column_image_path/down.yaml new file mode 100644 index 000000000..35e0068af --- /dev/null +++ b/hasura/migrations/1613767994173_alter_table_public_messages_add_column_image_path/down.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."messages" DROP COLUMN "image_path"; + type: run_sql diff --git a/hasura/migrations/1613767994173_alter_table_public_messages_add_column_image_path/up.yaml b/hasura/migrations/1613767994173_alter_table_public_messages_add_column_image_path/up.yaml new file mode 100644 index 000000000..335dd8063 --- /dev/null +++ b/hasura/migrations/1613767994173_alter_table_public_messages_add_column_image_path/up.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."messages" ADD COLUMN "image_path" jsonb NULL; + type: run_sql diff --git a/hasura/migrations/1613768005234_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1613768005234_update_permission_user_public_table_messages/down.yaml new file mode 100644 index 000000000..043c11b36 --- /dev/null +++ b/hasura/migrations/1613768005234_update_permission_user_public_table_messages/down.yaml @@ -0,0 +1,36 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_insert_permission +- args: + permission: + check: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - conversationid + - created_at + - id + - image + - isoutbound + - msid + - read + - status + - text + - updated_at + - userid + set: {} + role: user + table: + name: messages + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1613768005234_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1613768005234_update_permission_user_public_table_messages/up.yaml new file mode 100644 index 000000000..81a526283 --- /dev/null +++ b/hasura/migrations/1613768005234_update_permission_user_public_table_messages/up.yaml @@ -0,0 +1,37 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_insert_permission +- args: + permission: + check: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - conversationid + - created_at + - id + - image + - image_path + - isoutbound + - msid + - read + - status + - text + - updated_at + - userid + set: {} + role: user + table: + name: messages + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1613768012873_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1613768012873_update_permission_user_public_table_messages/down.yaml new file mode 100644 index 000000000..ae24478b6 --- /dev/null +++ b/hasura/migrations/1613768012873_update_permission_user_public_table_messages/down.yaml @@ -0,0 +1,37 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: true + columns: + - conversationid + - created_at + - id + - image + - isoutbound + - msid + - read + - status + - text + - updated_at + - userid + computed_fields: [] + filter: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: messages + schema: public + type: create_select_permission diff --git a/hasura/migrations/1613768012873_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1613768012873_update_permission_user_public_table_messages/up.yaml new file mode 100644 index 000000000..e0238e6f8 --- /dev/null +++ b/hasura/migrations/1613768012873_update_permission_user_public_table_messages/up.yaml @@ -0,0 +1,38 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: true + columns: + - conversationid + - created_at + - id + - image + - image_path + - isoutbound + - msid + - read + - status + - text + - updated_at + - userid + computed_fields: [] + filter: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: messages + schema: public + type: create_select_permission diff --git a/hasura/migrations/1613768023989_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1613768023989_update_permission_user_public_table_messages/down.yaml new file mode 100644 index 000000000..2cde6b1c2 --- /dev/null +++ b/hasura/migrations/1613768023989_update_permission_user_public_table_messages/down.yaml @@ -0,0 +1,35 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_update_permission +- args: + permission: + columns: + - conversationid + - created_at + - id + - image + - isoutbound + - msid + - read + - status + - text + - updated_at + filter: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: messages + schema: public + type: create_update_permission diff --git a/hasura/migrations/1613768023989_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1613768023989_update_permission_user_public_table_messages/up.yaml new file mode 100644 index 000000000..229ae219a --- /dev/null +++ b/hasura/migrations/1613768023989_update_permission_user_public_table_messages/up.yaml @@ -0,0 +1,36 @@ +- args: + role: user + table: + name: messages + schema: public + type: drop_update_permission +- args: + permission: + columns: + - conversationid + - created_at + - id + - image + - image_path + - isoutbound + - msid + - read + - status + - text + - updated_at + filter: + conversation: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: messages + schema: public + type: create_update_permission diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml index 097650649..0b8c13040 100644 --- a/hasura/migrations/metadata.yaml +++ b/hasura/migrations/metadata.yaml @@ -3057,17 +3057,17 @@ tables: - role: user permission: columns: + - conversationid + - created_at + - id - image - - isoutbound - - read - image_path + - isoutbound - msid + - read - status - text - - created_at - updated_at - - conversationid - - id filter: conversation: bodyshop: diff --git a/server/sms/receive.js b/server/sms/receive.js index 71e617e4e..44fee6251 100644 --- a/server/sms/receive.js +++ b/server/sms/receive.js @@ -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; + } +}; diff --git a/server/sms/send.js b/server/sms/send.js index 52b638374..dd14bb011 100644 --- a/server/sms/send.js +++ b/server/sms/send.js @@ -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 }], +// });