Skip to content

Add support for read msg status #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading