diff --git a/backends/rapidpro/backend_test.go b/backends/rapidpro/backend_test.go index b2fcfbda2..1ababf41b 100644 --- a/backends/rapidpro/backend_test.go +++ b/backends/rapidpro/backend_test.go @@ -518,6 +518,15 @@ func (ts *BackendTestSuite) TestMsgStatus() { ts.True(m.SentOn_.Equal(sentOn)) // no change ts.Equal(pq.StringArray([]string{string(clog1.UUID()), string(clog2.UUID()), string(clog3.UUID())}), m.LogUUIDs) + // update to READ using id + clog4 := updateStatusByID(10001, courier.MsgStatusRead, "") + + m = readMsgFromDB(ts.b, 10001) + ts.Equal(m.Status_, courier.MsgStatusRead) + ts.True(m.ModifiedOn_.After(now)) + ts.True(m.SentOn_.Equal(sentOn)) // no change + ts.Equal(pq.StringArray([]string{string(clog1.UUID()), string(clog2.UUID()), string(clog3.UUID()), string(clog4.UUID())}), m.LogUUIDs) + // no change for incoming messages updateStatusByID(10002, courier.MsgStatusSent, "") diff --git a/backends/rapidpro/status.go b/backends/rapidpro/status.go index 5793049b8..dfda32b03 100644 --- a/backends/rapidpro/status.go +++ b/backends/rapidpro/status.go @@ -90,7 +90,7 @@ UPDATE msgs_msg SET END, sent_on = CASE WHEN - s.status IN ('W', 'S', 'D') + s.status IN ('W', 'S', 'D', 'R') THEN COALESCE(sent_on, NOW()) ELSE diff --git a/handlers/kaleyra/handler.go b/handlers/kaleyra/handler.go index 0c1922957..a3f45f0a0 100644 --- a/handlers/kaleyra/handler.go +++ b/handlers/kaleyra/handler.go @@ -107,7 +107,7 @@ var statusMapping = map[string]courier.MsgStatus{ "0": courier.MsgStatusFailed, "sent": courier.MsgStatusWired, "delivered": courier.MsgStatusDelivered, - "read": courier.MsgStatusDelivered, + "read": courier.MsgStatusRead, } // receiveStatus is our HTTP handler function for outgoing messages statuses diff --git a/handlers/kaleyra/handler_test.go b/handlers/kaleyra/handler_test.go index 69f059d6c..52bba9c3e 100644 --- a/handlers/kaleyra/handler_test.go +++ b/handlers/kaleyra/handler_test.go @@ -73,7 +73,7 @@ var incomingCases = []IncomingTestCase{ URL: receiveStatusURL + "?id=58f86fab-85c5-4f7c-9b68-9c323248afc4%3A0&status=read", ExpectedRespStatus: 200, ExpectedBodyContains: `"type":"status"`, - ExpectedStatuses: []ExpectedStatus{{ExternalID: "58f86fab-85c5-4f7c-9b68-9c323248afc4:0", Status: courier.MsgStatusDelivered}}, + ExpectedStatuses: []ExpectedStatus{{ExternalID: "58f86fab-85c5-4f7c-9b68-9c323248afc4:0", Status: courier.MsgStatusRead}}, }, { Label: "Receive Invalid Status", diff --git a/handlers/meta/whatsapp/api.go b/handlers/meta/whatsapp/api.go index 5a36d008b..d0c25da01 100644 --- a/handlers/meta/whatsapp/api.go +++ b/handlers/meta/whatsapp/api.go @@ -6,7 +6,7 @@ import "github.com/nyaruka/courier" var StatusMapping = map[string]courier.MsgStatus{ "sent": courier.MsgStatusSent, "delivered": courier.MsgStatusDelivered, - "read": courier.MsgStatusDelivered, + "read": courier.MsgStatusRead, "failed": courier.MsgStatusFailed, } diff --git a/handlers/twiml/handlers.go b/handlers/twiml/handlers.go index 4ee43498d..575905486 100644 --- a/handlers/twiml/handlers.go +++ b/handlers/twiml/handlers.go @@ -107,7 +107,7 @@ var statusMapping = map[string]courier.MsgStatus{ "failed": courier.MsgStatusFailed, "sent": courier.MsgStatusSent, "delivered": courier.MsgStatusDelivered, - "read": courier.MsgStatusDelivered, + "read": courier.MsgStatusRead, "undelivered": courier.MsgStatusFailed, } diff --git a/handlers/twiml/handlers_test.go b/handlers/twiml/handlers_test.go index 76b4e279d..3481969c4 100644 --- a/handlers/twiml/handlers_test.go +++ b/handlers/twiml/handlers_test.go @@ -175,9 +175,9 @@ var testCases = []IncomingTestCase{ URL: statusURL, Data: statusRead, ExpectedRespStatus: 200, - ExpectedBodyContains: `"status":"D"`, + ExpectedBodyContains: `"status":"R"`, ExpectedStatuses: []ExpectedStatus{ - {ExternalID: "SMe287d7109a5a925f182f0e07fe5b223b", Status: courier.MsgStatusDelivered}, + {ExternalID: "SMe287d7109a5a925f182f0e07fe5b223b", Status: courier.MsgStatusRead}, }, PrepRequest: addValidSignature, }, diff --git a/handlers/whatsapp_legacy/handler.go b/handlers/whatsapp_legacy/handler.go index 18d8f836e..544c4b602 100644 --- a/handlers/whatsapp_legacy/handler.go +++ b/handlers/whatsapp_legacy/handler.go @@ -325,7 +325,7 @@ var waStatusMapping = map[string]courier.MsgStatus{ "sending": courier.MsgStatusWired, "sent": courier.MsgStatusSent, "delivered": courier.MsgStatusDelivered, - "read": courier.MsgStatusDelivered, + "read": courier.MsgStatusRead, "failed": courier.MsgStatusFailed, } diff --git a/handlers/zenvia/handlers.go b/handlers/zenvia/handlers.go index 9287eaf1b..3576b3e7b 100644 --- a/handlers/zenvia/handlers.go +++ b/handlers/zenvia/handlers.go @@ -134,7 +134,7 @@ var statusMapping = map[string]courier.MsgStatus{ "NOT_DELIVERED": courier.MsgStatusFailed, "SENT": courier.MsgStatusSent, "DELIVERED": courier.MsgStatusDelivered, - "READ": courier.MsgStatusDelivered, + "READ": courier.MsgStatusRead, } type statusPayload struct { diff --git a/status.go b/status.go index b729b8ce7..176864af4 100644 --- a/status.go +++ b/status.go @@ -13,6 +13,7 @@ const ( MsgStatusWired MsgStatus = "W" MsgStatusErrored MsgStatus = "E" MsgStatusDelivered MsgStatus = "D" + MsgStatusRead MsgStatus = "R" MsgStatusFailed MsgStatus = "F" NilMsgStatus MsgStatus = "" )