diff --git a/client/src/components/chat-conversation/chat-conversation.component.jsx b/client/src/components/chat-conversation/chat-conversation.component.jsx
index 59dcb66b1..662a8c9f3 100644
--- a/client/src/components/chat-conversation/chat-conversation.component.jsx
+++ b/client/src/components/chat-conversation/chat-conversation.component.jsx
@@ -54,7 +54,10 @@ export function ChatConversationComponent({
}}
size='small'>
{conversation.open ? (
-
+
) : (
)}
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 1fcd9db32..0da482dc7 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
@@ -16,14 +16,13 @@ const mapDispatchToProps = dispatch => ({
function ChatSendMessageComponent({ conversation, bodyshop, sendMessage }) {
const [message, setMessage] = useState("");
const { t } = useTranslation();
- console.log("message", message);
const handleEnter = () => {
- console.log("Sending that message ");
sendMessage({
to: conversation.phone,
body: message,
- messagingServiceSid: bodyshop.messagingservicesid
+ messagingServiceSid: bodyshop.messagingservicesid,
+ conversationid: conversation.id
});
};
diff --git a/client/src/redux/messaging/messaging.sagas.js b/client/src/redux/messaging/messaging.sagas.js
index a911a6406..b5af1f479 100644
--- a/client/src/redux/messaging/messaging.sagas.js
+++ b/client/src/redux/messaging/messaging.sagas.js
@@ -6,7 +6,8 @@ import axios from "axios";
export function* onSendMessage() {
yield takeLatest(MessagingActionTypes.SEND_MESSAGE, sendMessage);
}
-export function* sendMessage(payload) {
+export function* sendMessage({ payload }) {
+ console.log("In the saga.");
try {
console.log("Message Contents", payload);
axios.post("/sms/send", payload).then(response => {
diff --git a/hasura/migrations/1585179467940_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1585179467940_update_permission_user_public_table_messages/down.yaml
new file mode 100644
index 000000000..3d5f212d0
--- /dev/null
+++ b/hasura/migrations/1585179467940_update_permission_user_public_table_messages/down.yaml
@@ -0,0 +1,39 @@
+- 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:
+ - id
+ - created_at
+ - updated_at
+ - msid
+ - conversationid
+ - text
+ - image
+ - image_path
+ - sent
+ - delivered
+ - isoutbound
+ localPresets:
+ - key: ""
+ value: ""
+ set: {}
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: create_insert_permission
diff --git a/hasura/migrations/1585179467940_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1585179467940_update_permission_user_public_table_messages/up.yaml
new file mode 100644
index 000000000..2416c2c1a
--- /dev/null
+++ b/hasura/migrations/1585179467940_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
+ - text
+ - updated_at
+ localPresets:
+ - key: ""
+ value: ""
+ set: {}
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: create_insert_permission
diff --git a/hasura/migrations/1585179475576_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1585179475576_update_permission_user_public_table_messages/down.yaml
new file mode 100644
index 000000000..24e4f5a60
--- /dev/null
+++ b/hasura/migrations/1585179475576_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: false
+ columns:
+ - delivered
+ - image
+ - isoutbound
+ - sent
+ - image_path
+ - msid
+ - text
+ - created_at
+ - updated_at
+ - conversationid
+ - id
+ 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/1585179475576_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1585179475576_update_permission_user_public_table_messages/up.yaml
new file mode 100644
index 000000000..30cabb081
--- /dev/null
+++ b/hasura/migrations/1585179475576_update_permission_user_public_table_messages/up.yaml
@@ -0,0 +1,35 @@
+- args:
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: drop_select_permission
+- args:
+ permission:
+ allow_aggregations: false
+ columns:
+ - conversationid
+ - created_at
+ - id
+ - image
+ - image_path
+ - isoutbound
+ - msid
+ - text
+ - updated_at
+ 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/1585179482717_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1585179482717_update_permission_user_public_table_messages/down.yaml
new file mode 100644
index 000000000..29938a450
--- /dev/null
+++ b/hasura/migrations/1585179482717_update_permission_user_public_table_messages/down.yaml
@@ -0,0 +1,39 @@
+- args:
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: drop_update_permission
+- args:
+ permission:
+ columns:
+ - delivered
+ - image
+ - isoutbound
+ - sent
+ - image_path
+ - msid
+ - text
+ - created_at
+ - updated_at
+ - conversationid
+ - id
+ filter:
+ conversation:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ localPresets:
+ - key: ""
+ value: ""
+ set: {}
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: create_update_permission
diff --git a/hasura/migrations/1585179482717_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1585179482717_update_permission_user_public_table_messages/up.yaml
new file mode 100644
index 000000000..cec8b33a7
--- /dev/null
+++ b/hasura/migrations/1585179482717_update_permission_user_public_table_messages/up.yaml
@@ -0,0 +1,37 @@
+- args:
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: drop_update_permission
+- args:
+ permission:
+ columns:
+ - conversationid
+ - created_at
+ - id
+ - image
+ - image_path
+ - isoutbound
+ - msid
+ - text
+ - updated_at
+ filter:
+ conversation:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ localPresets:
+ - key: ""
+ value: ""
+ set: {}
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: create_update_permission
diff --git a/hasura/migrations/1585179490323_alter_table_public_messages_drop_column_delivered/down.yaml b/hasura/migrations/1585179490323_alter_table_public_messages_drop_column_delivered/down.yaml
new file mode 100644
index 000000000..23f6819fa
--- /dev/null
+++ b/hasura/migrations/1585179490323_alter_table_public_messages_drop_column_delivered/down.yaml
@@ -0,0 +1,15 @@
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" ADD COLUMN "delivered" bool;
+ type: run_sql
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" ALTER COLUMN "delivered" DROP NOT NULL;
+ type: run_sql
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" ALTER COLUMN "delivered" SET DEFAULT false;
+ type: run_sql
diff --git a/hasura/migrations/1585179490323_alter_table_public_messages_drop_column_delivered/up.yaml b/hasura/migrations/1585179490323_alter_table_public_messages_drop_column_delivered/up.yaml
new file mode 100644
index 000000000..051f0ff76
--- /dev/null
+++ b/hasura/migrations/1585179490323_alter_table_public_messages_drop_column_delivered/up.yaml
@@ -0,0 +1,5 @@
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" DROP COLUMN "delivered" CASCADE;
+ type: run_sql
diff --git a/hasura/migrations/1585179498362_alter_table_public_messages_drop_column_sent/down.yaml b/hasura/migrations/1585179498362_alter_table_public_messages_drop_column_sent/down.yaml
new file mode 100644
index 000000000..3beef333b
--- /dev/null
+++ b/hasura/migrations/1585179498362_alter_table_public_messages_drop_column_sent/down.yaml
@@ -0,0 +1,15 @@
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" ADD COLUMN "sent" bool;
+ type: run_sql
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" ALTER COLUMN "sent" DROP NOT NULL;
+ type: run_sql
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" ALTER COLUMN "sent" SET DEFAULT false;
+ type: run_sql
diff --git a/hasura/migrations/1585179498362_alter_table_public_messages_drop_column_sent/up.yaml b/hasura/migrations/1585179498362_alter_table_public_messages_drop_column_sent/up.yaml
new file mode 100644
index 000000000..e2549f514
--- /dev/null
+++ b/hasura/migrations/1585179498362_alter_table_public_messages_drop_column_sent/up.yaml
@@ -0,0 +1,5 @@
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" DROP COLUMN "sent" CASCADE;
+ type: run_sql
diff --git a/hasura/migrations/1585179618401_alter_table_public_messages_add_column_status/down.yaml b/hasura/migrations/1585179618401_alter_table_public_messages_add_column_status/down.yaml
new file mode 100644
index 000000000..2d3eb14b7
--- /dev/null
+++ b/hasura/migrations/1585179618401_alter_table_public_messages_add_column_status/down.yaml
@@ -0,0 +1,5 @@
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" DROP COLUMN "status";
+ type: run_sql
diff --git a/hasura/migrations/1585179618401_alter_table_public_messages_add_column_status/up.yaml b/hasura/migrations/1585179618401_alter_table_public_messages_add_column_status/up.yaml
new file mode 100644
index 000000000..95d0f93bb
--- /dev/null
+++ b/hasura/migrations/1585179618401_alter_table_public_messages_add_column_status/up.yaml
@@ -0,0 +1,6 @@
+- args:
+ cascade: false
+ read_only: false
+ sql: ALTER TABLE "public"."messages" ADD COLUMN "status" text NOT NULL DEFAULT
+ 'posted';
+ type: run_sql
diff --git a/hasura/migrations/1585179627356_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1585179627356_update_permission_user_public_table_messages/down.yaml
new file mode 100644
index 000000000..2416c2c1a
--- /dev/null
+++ b/hasura/migrations/1585179627356_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
+ - text
+ - updated_at
+ localPresets:
+ - key: ""
+ value: ""
+ set: {}
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: create_insert_permission
diff --git a/hasura/migrations/1585179627356_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1585179627356_update_permission_user_public_table_messages/up.yaml
new file mode 100644
index 000000000..1d1eaa297
--- /dev/null
+++ b/hasura/migrations/1585179627356_update_permission_user_public_table_messages/up.yaml
@@ -0,0 +1,38 @@
+- 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:
+ - id
+ - created_at
+ - updated_at
+ - msid
+ - conversationid
+ - text
+ - image
+ - image_path
+ - isoutbound
+ - status
+ localPresets:
+ - key: ""
+ value: ""
+ set: {}
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: create_insert_permission
diff --git a/hasura/migrations/1585179632891_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1585179632891_update_permission_user_public_table_messages/down.yaml
new file mode 100644
index 000000000..30cabb081
--- /dev/null
+++ b/hasura/migrations/1585179632891_update_permission_user_public_table_messages/down.yaml
@@ -0,0 +1,35 @@
+- args:
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: drop_select_permission
+- args:
+ permission:
+ allow_aggregations: false
+ columns:
+ - conversationid
+ - created_at
+ - id
+ - image
+ - image_path
+ - isoutbound
+ - msid
+ - text
+ - updated_at
+ 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/1585179632891_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1585179632891_update_permission_user_public_table_messages/up.yaml
new file mode 100644
index 000000000..cfc1aa1a4
--- /dev/null
+++ b/hasura/migrations/1585179632891_update_permission_user_public_table_messages/up.yaml
@@ -0,0 +1,36 @@
+- args:
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: drop_select_permission
+- args:
+ permission:
+ allow_aggregations: false
+ columns:
+ - conversationid
+ - created_at
+ - id
+ - image
+ - image_path
+ - isoutbound
+ - msid
+ - status
+ - text
+ - updated_at
+ 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/1585179638124_update_permission_user_public_table_messages/down.yaml b/hasura/migrations/1585179638124_update_permission_user_public_table_messages/down.yaml
new file mode 100644
index 000000000..cec8b33a7
--- /dev/null
+++ b/hasura/migrations/1585179638124_update_permission_user_public_table_messages/down.yaml
@@ -0,0 +1,37 @@
+- args:
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: drop_update_permission
+- args:
+ permission:
+ columns:
+ - conversationid
+ - created_at
+ - id
+ - image
+ - image_path
+ - isoutbound
+ - msid
+ - text
+ - updated_at
+ filter:
+ conversation:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ localPresets:
+ - key: ""
+ value: ""
+ set: {}
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: create_update_permission
diff --git a/hasura/migrations/1585179638124_update_permission_user_public_table_messages/up.yaml b/hasura/migrations/1585179638124_update_permission_user_public_table_messages/up.yaml
new file mode 100644
index 000000000..11ebdccfd
--- /dev/null
+++ b/hasura/migrations/1585179638124_update_permission_user_public_table_messages/up.yaml
@@ -0,0 +1,38 @@
+- args:
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: drop_update_permission
+- args:
+ permission:
+ columns:
+ - image
+ - isoutbound
+ - 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
+ localPresets:
+ - key: ""
+ value: ""
+ set: {}
+ role: user
+ table:
+ name: messages
+ schema: public
+ type: create_update_permission
diff --git a/server.js b/server.js
index b4fb77a3a..c2c016495 100644
--- a/server.js
+++ b/server.js
@@ -40,7 +40,11 @@ app.post(
var smsSend = require("./server/sms/send");
app.post("/sms/send", smsSend.send);
var smsStatus = require("./server/sms/status");
-app.post("/sms/status", smsStatus.status);
+app.post(
+ "/sms/status",
+ twilio.webhook({ validate: process.env.NODE_ENV === "PRODUCTION" }),
+ smsStatus.status
+);
var downloadImages = require("./download-images");
app.get("/downloadImages", downloadImages.downloadImages);
diff --git a/server/graphql-client/queries.js b/server/graphql-client/queries.js
index e3a4c7a66..5392db6a3 100644
--- a/server/graphql-client/queries.js
+++ b/server/graphql-client/queries.js
@@ -21,3 +21,13 @@ mutation INSERT_MESSAGE($msg: [messages_insert_input!]!) {
}
}
`;
+
+exports.UPDATE_MESSAGE_STATUS = `
+mutation UPDATE_MESSAGE($msid: String!, $fields: messages_set_input!) {
+ update_messages(where: { msid: { _eq: $msid } }, _set: $fields) {
+ returning {
+ id
+ }
+ }
+ }
+ `;
diff --git a/server/sms/send.js b/server/sms/send.js
index 01f909713..46b500c00 100644
--- a/server/sms/send.js
+++ b/server/sms/send.js
@@ -1,16 +1,24 @@
require("dotenv").config();
const twilio = require("twilio");
const phone = require("phone");
+const queries = require("../graphql-client/queries");
const client = twilio(
process.env.TWILIO_AUTH_TOKEN,
process.env.TWILIO_AUTH_KEY
);
+const gqlClient = require("../graphql-client/graphql-client").client;
exports.send = (req, res) => {
console.log("Sending an SMS!");
const { to, messagingServiceSid, body, conversationid } = req.body;
-
+ console.log(
+ "to, messagingServiceSid, body, conversationid",
+ to,
+ messagingServiceSid,
+ body,
+ conversationid
+ );
if (!!to && !!messagingServiceSid && !!body && !!conversationid) {
client.messages
.create({
@@ -25,16 +33,20 @@ exports.send = (req, res) => {
conversationid,
isoutbound: true
};
- client
+ gqlClient
.request(queries.INSERT_MESSAGE, { msg: newMessage })
.then(r2 => {
res.sendStatus(200);
})
.catch(e2 => {
- res.json({ success: false, message: e2 });
+ console.log("e2", e2);
+ //res.json({ success: false, message: e2 });
});
})
- .catch(error => res.json({ success: false, message: error }));
+ .catch(e1 => {
+ //res.json({ success: false, message: error });
+ console.log("e1", e1);
+ });
} else {
res.json({ success: false, message: "Missing required parameter(s)." });
}
diff --git a/server/sms/status.js b/server/sms/status.js
index 5cbc312ce..8522f5e2d 100644
--- a/server/sms/status.js
+++ b/server/sms/status.js
@@ -4,8 +4,18 @@ const queries = require("../graphql-client/queries");
const phone = require("phone");
exports.status = (req, res) => {
- //Perform request validation
- console.log("Inbound Status Update: ", JSON.stringify(req.body));
+ const { SmsSid, SmsStatus } = req.body;
+ client
+ .request(queries.UPDATE_MESSAGE_STATUS, {
+ msid: SmsSid,
+ fields: { status: SmsStatus }
+ })
+ .then(response => {
+ console.log("Message Updated");
+ })
+ .catch(error => {
+ console.log("Error updating message status", error);
+ });
res.sendStatus(200);
};