diff --git a/backends/rapidpro/backend_test.go b/backends/rapidpro/backend_test.go index 5b2c14462..61faaf4b8 100644 --- a/backends/rapidpro/backend_test.go +++ b/backends/rapidpro/backend_test.go @@ -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)}) + ts.assertQueuedContactTask(ContactID(100), "msg_deleted", map[string]any{"msg_id": float64(10002)}) } func (ts *BackendTestSuite) TestContact() { @@ -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()), @@ -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_), }) } diff --git a/backends/rapidpro/task.go b/backends/rapidpro/task.go index f9967a355..98b4669cc 100644 --- a/backends/rapidpro/task.go +++ b/backends/rapidpro/task.go @@ -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(), @@ -32,8 +29,8 @@ 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_, + "event_type": e.EventType_, "urn_id": e.ContactURNID_, "channel_id": e.ChannelID_, "extra": e.Extra(), @@ -41,6 +38,9 @@ func queueChannelEvent(rc redis.Conn, c *Contact, e *ChannelEvent) error { "occurred_on": e.OccurredOn_, "created_on": e.CreatedOn_, } + if e.OptInID_ != 0 { + body["optin_id"] = e.OptInID_ + } switch e.EventType() { case courier.EventTypeStopContact: @@ -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