Skip to content

Commit

Permalink
Merge pull request #735 from nyaruka/status-read
Browse files Browse the repository at this point in the history
Add support for read msg status
  • Loading branch information
rowanseymour authored Apr 29, 2024
2 parents 334e3e6 + 3bfd3be commit 7b116e4
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 9 deletions.
9 changes: 9 additions & 0 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")

Expand Down
2 changes: 1 addition & 1 deletion backends/rapidpro/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion handlers/kaleyra/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion handlers/kaleyra/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion handlers/meta/whatsapp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion handlers/twiml/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 2 additions & 2 deletions handlers/twiml/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion handlers/whatsapp_legacy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion handlers/zenvia/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
MsgStatusWired MsgStatus = "W"
MsgStatusErrored MsgStatus = "E"
MsgStatusDelivered MsgStatus = "D"
MsgStatusRead MsgStatus = "R"
MsgStatusFailed MsgStatus = "F"
NilMsgStatus MsgStatus = ""
)
Expand Down

0 comments on commit 7b116e4

Please sign in to comment.