Skip to content

Queue all channel events to mailroom as a single task type #724

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
2 changes: 1 addition & 1 deletion backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ func (ts *BackendTestSuite) TestMailroomEvents() {
ts.Equal(contact.ID_, dbE.ContactID_)
ts.Equal(contact.URNID_, dbE.ContactURNID_)

ts.assertQueuedContactTask(contact.ID_, "referral", map[string]any{
ts.assertQueuedContactTask(contact.ID_, "channel_event", map[string]any{
"event_id": float64(dbE.ID_),
"event_type": "referral",
"channel_id": float64(10),
Expand Down
20 changes: 1 addition & 19 deletions backends/rapidpro/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,7 @@ func queueChannelEvent(rc redis.Conn, c *Contact, e *ChannelEvent) error {
body["optin_id"] = e.OptInID_
}

switch e.EventType() {
case courier.EventTypeStopContact:
return queueMailroomTask(rc, "stop_contact", e.OrgID_, e.ContactID_, body)
case courier.EventTypeWelcomeMessage:
return queueMailroomTask(rc, "welcome_message", e.OrgID_, e.ContactID_, body)
case courier.EventTypeReferral:
return queueMailroomTask(rc, "referral", e.OrgID_, e.ContactID_, body)
case courier.EventTypeNewConversation:
return queueMailroomTask(rc, "new_conversation", e.OrgID_, e.ContactID_, body)
case courier.EventTypeOptIn:
return queueMailroomTask(rc, "optin", e.OrgID_, e.ContactID_, body)
case courier.EventTypeOptOut:
return queueMailroomTask(rc, "optout", e.OrgID_, e.ContactID_, body)
default:
return fmt.Errorf("unknown event type: %s", e.EventType())
}
return queueMailroomTask(rc, "channel_event", e.OrgID_, e.ContactID_, body)
}

func queueMsgDeleted(rc redis.Conn, ch *Channel, msgID courier.MsgID, contactID ContactID) error {
Expand All @@ -70,15 +55,13 @@ func queueMailroomTask(rc redis.Conn, taskType string, orgID OrgID, contactID Co
// create our event task
eventJSON := jsonx.MustMarshal(mrTask{
Type: taskType,
OrgID: orgID,
Task: body,
QueuedOn: time.Now(),
})

// create our org task
contactJSON := jsonx.MustMarshal(mrTask{
Type: "handle_contact_event",
OrgID: orgID,
Task: mrContactTask{ContactID: contactID},
QueuedOn: time.Now(),
})
Expand All @@ -103,7 +86,6 @@ type mrContactTask struct {

type mrTask struct {
Type string `json:"type"`
OrgID OrgID `json:"org_id"`
Task any `json:"task"`
QueuedOn time.Time `json:"queued_on"`
}
Loading