Skip to content

Commit a1af0c3

Browse files
authored
Merge pull request #724 from nyaruka/single_channel_event_task
Queue all channel events to mailroom as a single task type
2 parents 5033ef5 + e27df19 commit a1af0c3

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed

Diff for: backends/rapidpro/backend_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ func (ts *BackendTestSuite) TestMailroomEvents() {
13321332
ts.Equal(contact.ID_, dbE.ContactID_)
13331333
ts.Equal(contact.URNID_, dbE.ContactURNID_)
13341334

1335-
ts.assertQueuedContactTask(contact.ID_, "referral", map[string]any{
1335+
ts.assertQueuedContactTask(contact.ID_, "channel_event", map[string]any{
13361336
"event_id": float64(dbE.ID_),
13371337
"event_type": "referral",
13381338
"channel_id": float64(10),

Diff for: backends/rapidpro/task.go

+1-19
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,7 @@ func queueChannelEvent(rc redis.Conn, c *Contact, e *ChannelEvent) error {
4242
body["optin_id"] = e.OptInID_
4343
}
4444

45-
switch e.EventType() {
46-
case courier.EventTypeStopContact:
47-
return queueMailroomTask(rc, "stop_contact", e.OrgID_, e.ContactID_, body)
48-
case courier.EventTypeWelcomeMessage:
49-
return queueMailroomTask(rc, "welcome_message", e.OrgID_, e.ContactID_, body)
50-
case courier.EventTypeReferral:
51-
return queueMailroomTask(rc, "referral", e.OrgID_, e.ContactID_, body)
52-
case courier.EventTypeNewConversation:
53-
return queueMailroomTask(rc, "new_conversation", e.OrgID_, e.ContactID_, body)
54-
case courier.EventTypeOptIn:
55-
return queueMailroomTask(rc, "optin", e.OrgID_, e.ContactID_, body)
56-
case courier.EventTypeOptOut:
57-
return queueMailroomTask(rc, "optout", e.OrgID_, e.ContactID_, body)
58-
default:
59-
return fmt.Errorf("unknown event type: %s", e.EventType())
60-
}
45+
return queueMailroomTask(rc, "channel_event", e.OrgID_, e.ContactID_, body)
6146
}
6247

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

7862
// create our org task
7963
contactJSON := jsonx.MustMarshal(mrTask{
8064
Type: "handle_contact_event",
81-
OrgID: orgID,
8265
Task: mrContactTask{ContactID: contactID},
8366
QueuedOn: time.Now(),
8467
})
@@ -103,7 +86,6 @@ type mrContactTask struct {
10386

10487
type mrTask struct {
10588
Type string `json:"type"`
106-
OrgID OrgID `json:"org_id"`
10789
Task any `json:"task"`
10890
QueuedOn time.Time `json:"queued_on"`
10991
}

0 commit comments

Comments
 (0)