Skip to content

Update payloads for tasks queued to mailroom #723

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 1 commit into from
Mar 28, 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
12 changes: 5 additions & 7 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (ts *BackendTestSuite) TestDeleteMsgByExternalID() {
err = ts.b.DeleteMsgByExternalID(ctx, knChannel, "ext2")
ts.Nil(err)

ts.assertQueuedContactTask(ContactID(100), "msg_deleted", map[string]any{"org_id": float64(1), "msg_id": float64(10002)})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to repeat org_id or contact_id in the task payload... mailroom gets that from the queue

ts.assertQueuedContactTask(ContactID(100), "msg_deleted", map[string]any{"msg_id": float64(10002)})
}

func (ts *BackendTestSuite) TestContact() {
Expand Down Expand Up @@ -1169,8 +1169,6 @@ func (ts *BackendTestSuite) TestWriteMsg() {
ts.NoError(err)

ts.assertQueuedContactTask(msg.ContactID_, "msg_event", map[string]any{
"contact_id": float64(contact.ID_),
"org_id": float64(1),
"channel_id": float64(10),
"msg_id": float64(msg.ID_),
"msg_uuid": string(msg.UUID()),
Expand Down Expand Up @@ -1335,13 +1333,13 @@ func (ts *BackendTestSuite) TestMailroomEvents() {
ts.Equal(contact.URNID_, dbE.ContactURNID_)

ts.assertQueuedContactTask(contact.ID_, "referral", map[string]any{
"event_id": float64(dbE.ID_),
"event_type": "referral",
"channel_id": float64(10),
"contact_id": float64(contact.ID_),
"urn_id": float64(contact.URNID_),
"extra": map[string]any{"ref_id": "12345"},
"new_contact": contact.IsNew_,
"new_contact": false,
"occurred_on": "2020-08-05T13:30:00.123456789Z",
"org_id": float64(1),
"urn_id": float64(contact.URNID_),
})
}

Expand Down
12 changes: 6 additions & 6 deletions backends/rapidpro/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import (
func queueMsgHandling(rc redis.Conn, c *Contact, m *Msg) error {
channel := m.Channel().(*Channel)

// queue to mailroom
body := map[string]any{
"contact_id": c.ID_,
"org_id": channel.OrgID_,
"channel_id": channel.ID_,
"msg_id": m.ID_,
"msg_uuid": m.UUID(),
Expand All @@ -32,15 +29,18 @@ func queueMsgHandling(rc redis.Conn, c *Contact, m *Msg) error {

func queueChannelEvent(rc redis.Conn, c *Contact, e *ChannelEvent) error {
body := map[string]any{
"org_id": e.OrgID_,
"contact_id": e.ContactID_,
"event_id": e.ID_,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we should some day model whether channel events are handled.. i.e. have mailroom update their status like we do for messages.

"event_type": e.EventType_,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to switch these to all be a single channel_event task type, so step one is putting event_type in the payload

"urn_id": e.ContactURNID_,
"channel_id": e.ChannelID_,
"extra": e.Extra(),
"new_contact": c.IsNew_,
"occurred_on": e.OccurredOn_,
"created_on": e.CreatedOn_,
}
if e.OptInID_ != 0 {
body["optin_id"] = e.OptInID_
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best I can tell we're not doing optin triggers correctly in the engine because this isn't being passed - the triggers work but @optin is exposed in expressions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

switch e.EventType() {
case courier.EventTypeStopContact:
Expand All @@ -61,7 +61,7 @@ func queueChannelEvent(rc redis.Conn, c *Contact, e *ChannelEvent) error {
}

func queueMsgDeleted(rc redis.Conn, ch *Channel, msgID courier.MsgID, contactID ContactID) error {
return queueMailroomTask(rc, "msg_deleted", ch.OrgID_, contactID, map[string]any{"org_id": ch.OrgID_, "msg_id": msgID})
return queueMailroomTask(rc, "msg_deleted", ch.OrgID_, contactID, map[string]any{"msg_id": msgID})
}

// queueMailroomTask queues the passed in task to mailroom. Mailroom processes both messages and
Expand Down
Loading