Skip to content

Commit 7b116e4

Browse files
authored
Merge pull request #735 from nyaruka/status-read
Add support for read msg status
2 parents 334e3e6 + 3bfd3be commit 7b116e4

File tree

10 files changed

+19
-9
lines changed

10 files changed

+19
-9
lines changed

Diff for: backends/rapidpro/backend_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,15 @@ func (ts *BackendTestSuite) TestMsgStatus() {
518518
ts.True(m.SentOn_.Equal(sentOn)) // no change
519519
ts.Equal(pq.StringArray([]string{string(clog1.UUID()), string(clog2.UUID()), string(clog3.UUID())}), m.LogUUIDs)
520520

521+
// update to READ using id
522+
clog4 := updateStatusByID(10001, courier.MsgStatusRead, "")
523+
524+
m = readMsgFromDB(ts.b, 10001)
525+
ts.Equal(m.Status_, courier.MsgStatusRead)
526+
ts.True(m.ModifiedOn_.After(now))
527+
ts.True(m.SentOn_.Equal(sentOn)) // no change
528+
ts.Equal(pq.StringArray([]string{string(clog1.UUID()), string(clog2.UUID()), string(clog3.UUID()), string(clog4.UUID())}), m.LogUUIDs)
529+
521530
// no change for incoming messages
522531
updateStatusByID(10002, courier.MsgStatusSent, "")
523532

Diff for: backends/rapidpro/status.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ UPDATE msgs_msg SET
9090
END,
9191
sent_on = CASE
9292
WHEN
93-
s.status IN ('W', 'S', 'D')
93+
s.status IN ('W', 'S', 'D', 'R')
9494
THEN
9595
COALESCE(sent_on, NOW())
9696
ELSE

Diff for: handlers/kaleyra/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var statusMapping = map[string]courier.MsgStatus{
107107
"0": courier.MsgStatusFailed,
108108
"sent": courier.MsgStatusWired,
109109
"delivered": courier.MsgStatusDelivered,
110-
"read": courier.MsgStatusDelivered,
110+
"read": courier.MsgStatusRead,
111111
}
112112

113113
// receiveStatus is our HTTP handler function for outgoing messages statuses

Diff for: handlers/kaleyra/handler_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var incomingCases = []IncomingTestCase{
7373
URL: receiveStatusURL + "?id=58f86fab-85c5-4f7c-9b68-9c323248afc4%3A0&status=read",
7474
ExpectedRespStatus: 200,
7575
ExpectedBodyContains: `"type":"status"`,
76-
ExpectedStatuses: []ExpectedStatus{{ExternalID: "58f86fab-85c5-4f7c-9b68-9c323248afc4:0", Status: courier.MsgStatusDelivered}},
76+
ExpectedStatuses: []ExpectedStatus{{ExternalID: "58f86fab-85c5-4f7c-9b68-9c323248afc4:0", Status: courier.MsgStatusRead}},
7777
},
7878
{
7979
Label: "Receive Invalid Status",

Diff for: handlers/meta/whatsapp/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "github.com/nyaruka/courier"
66
var StatusMapping = map[string]courier.MsgStatus{
77
"sent": courier.MsgStatusSent,
88
"delivered": courier.MsgStatusDelivered,
9-
"read": courier.MsgStatusDelivered,
9+
"read": courier.MsgStatusRead,
1010
"failed": courier.MsgStatusFailed,
1111
}
1212

Diff for: handlers/twiml/handlers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ var statusMapping = map[string]courier.MsgStatus{
107107
"failed": courier.MsgStatusFailed,
108108
"sent": courier.MsgStatusSent,
109109
"delivered": courier.MsgStatusDelivered,
110-
"read": courier.MsgStatusDelivered,
110+
"read": courier.MsgStatusRead,
111111
"undelivered": courier.MsgStatusFailed,
112112
}
113113

Diff for: handlers/twiml/handlers_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ var testCases = []IncomingTestCase{
175175
URL: statusURL,
176176
Data: statusRead,
177177
ExpectedRespStatus: 200,
178-
ExpectedBodyContains: `"status":"D"`,
178+
ExpectedBodyContains: `"status":"R"`,
179179
ExpectedStatuses: []ExpectedStatus{
180-
{ExternalID: "SMe287d7109a5a925f182f0e07fe5b223b", Status: courier.MsgStatusDelivered},
180+
{ExternalID: "SMe287d7109a5a925f182f0e07fe5b223b", Status: courier.MsgStatusRead},
181181
},
182182
PrepRequest: addValidSignature,
183183
},

Diff for: handlers/whatsapp_legacy/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ var waStatusMapping = map[string]courier.MsgStatus{
325325
"sending": courier.MsgStatusWired,
326326
"sent": courier.MsgStatusSent,
327327
"delivered": courier.MsgStatusDelivered,
328-
"read": courier.MsgStatusDelivered,
328+
"read": courier.MsgStatusRead,
329329
"failed": courier.MsgStatusFailed,
330330
}
331331

Diff for: handlers/zenvia/handlers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var statusMapping = map[string]courier.MsgStatus{
134134
"NOT_DELIVERED": courier.MsgStatusFailed,
135135
"SENT": courier.MsgStatusSent,
136136
"DELIVERED": courier.MsgStatusDelivered,
137-
"READ": courier.MsgStatusDelivered,
137+
"READ": courier.MsgStatusRead,
138138
}
139139

140140
type statusPayload struct {

Diff for: status.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const (
1313
MsgStatusWired MsgStatus = "W"
1414
MsgStatusErrored MsgStatus = "E"
1515
MsgStatusDelivered MsgStatus = "D"
16+
MsgStatusRead MsgStatus = "R"
1617
MsgStatusFailed MsgStatus = "F"
1718
NilMsgStatus MsgStatus = ""
1819
)

0 commit comments

Comments
 (0)