Skip to content

Commit

Permalink
Merge pull request #55 from nyaruka/msg_json_diet
Browse files Browse the repository at this point in the history
Remove fields from courier payload that it doesn't use
  • Loading branch information
rowanseymour authored Apr 17, 2023
2 parents 61187d2 + 3dfa6ff commit 25dbd8e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 43 deletions.
16 changes: 0 additions & 16 deletions core/msgio/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,13 @@ type Msg struct {
QuickReplies []string `json:"quick_replies,omitempty"`
Locale envs.Locale `json:"locale,omitempty"`
HighPriority bool `json:"high_priority"`
Direction models.MsgDirection `json:"direction"`
Status models.MsgStatus `json:"status"`
MsgCount int `json:"tps_cost"`
CreatedOn time.Time `json:"created_on"`
ModifiedOn time.Time `json:"modified_on"`
ChannelID models.ChannelID `json:"channel_id"`
ChannelUUID assets.ChannelUUID `json:"channel_uuid"`
ContactID models.ContactID `json:"contact_id"`
ContactURNID *models.URNID `json:"contact_urn_id"`
URN urns.URN `json:"urn"`
URNAuth string `json:"urn_auth,omitempty"`
SentOn *time.Time `json:"sent_on"`
QueuedOn time.Time `json:"queued_on"`
ErrorCount int `json:"error_count"`
NextAttempt *time.Time `json:"next_attempt"`
Metadata map[string]any `json:"metadata,omitempty"`
Flow *assets.FlowReference `json:"flow,omitempty"`
ResponseToExternalID string `json:"response_to_external_id,omitempty"`
Expand Down Expand Up @@ -89,21 +81,13 @@ func NewCourierMsg(oa *models.OrgAssets, m *models.Msg, channel *models.Channel)
QuickReplies: m.QuickReplies(),
Locale: m.Locale(),
HighPriority: m.HighPriority(),
Direction: m.Direction(),
Status: m.Status(),
MsgCount: m.MsgCount(),
CreatedOn: m.CreatedOn(),
ModifiedOn: m.ModifiedOn(),
ChannelID: m.ChannelID(),
ChannelUUID: channel.UUID(),
ContactID: m.ContactID(),
ContactURNID: m.ContactURNID(),
URN: m.URN(),
URNAuth: string(m.URNAuth()),
SentOn: m.SentOn(),
QueuedOn: m.QueuedOn(),
ErrorCount: m.ErrorCount(),
NextAttempt: m.NextAttempt(),
Metadata: m.Metadata(),
Flow: flowRef,
ResponseToExternalID: string(m.ResponseToExternalID),
Expand Down
30 changes: 3 additions & 27 deletions core/msgio/courier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,10 @@ func TestNewCourierMsg(t *testing.T) {
"attachments": [
"image/jpeg:https://dl-foo.com/image.jpg"
],
"channel_id": 10000,
"channel_uuid": "74729f45-7f29-4868-9dc4-90e491e3c7d8",
"contact_id": 10000,
"contact_urn_id": 10000,
"created_on": "2021-11-09T14:03:30Z",
"direction": "O",
"error_count": 0,
"flow": {"uuid": "9de3663f-c5c5-4c92-9f45-ecbc09abcc85", "name": "Favorites"},
"high_priority": false,
"id": %d,
Expand All @@ -93,23 +90,18 @@ func TestNewCourierMsg(t *testing.T) {
},
"topic": "purchase"
},
"modified_on": %s,
"next_attempt": null,
"org_id": 1,
"queued_on": %s,
"quick_replies": [
"yes",
"no"
],
"sent_on": null,
"session_id": %d,
"session_status": "W",
"status": "Q",
"text": "Hi there",
"tps_cost": 2,
"urn": "tel:+250700000001?id=10000",
"uuid": "%s"
}`, msg1.ID(), jsonx.MustMarshal(msg1.ModifiedOn()), jsonx.MustMarshal(msg1.QueuedOn()), session.ID(), msg1.UUID())), marshaled)
}`, msg1.ID(), session.ID(), msg1.UUID())), marshaled)

// create a priority flow message.. i.e. the session is responding to an incoming message
flowMsg2 := flows.NewMsgOut(
Expand All @@ -135,30 +127,22 @@ func TestNewCourierMsg(t *testing.T) {
marshaled = jsonx.MustMarshal(cmsg2)

test.AssertEqualJSON(t, []byte(fmt.Sprintf(`{
"channel_id": 10000,
"channel_uuid": "74729f45-7f29-4868-9dc4-90e491e3c7d8",
"contact_id": 10000,
"contact_urn_id": 10000,
"created_on": "2021-11-09T14:03:30Z",
"direction": "O",
"error_count": 0,
"flow": {"uuid": "9de3663f-c5c5-4c92-9f45-ecbc09abcc85", "name": "Favorites"},
"response_to_external_id": "EX123",
"high_priority": true,
"id": %d,
"modified_on": %s,
"next_attempt": null,
"org_id": 1,
"queued_on": %s,
"sent_on": null,
"session_id": %d,
"session_status": "W",
"status": "Q",
"text": "Hi there",
"tps_cost": 1,
"urn": "tel:+250700000001?id=10000",
"uuid": "%s"
}`, msg2.ID(), jsonx.MustMarshal(msg2.ModifiedOn()), jsonx.MustMarshal(msg2.QueuedOn()), session.ID(), msg2.UUID())), marshaled)
}`, msg2.ID(), session.ID(), msg2.UUID())), marshaled)

// try a broadcast message which won't have session and flow fields set
bcastID := testdata.InsertBroadcast(rt, testdata.Org1, `eng`, map[envs.Language]string{`eng`: "Blast"}, models.NilScheduleID, []*testdata.Contact{testdata.Cathy}, nil)
Expand All @@ -175,26 +159,18 @@ func TestNewCourierMsg(t *testing.T) {
marshaled = jsonx.MustMarshal(cmsg3)

test.AssertEqualJSON(t, []byte(fmt.Sprintf(`{
"channel_id": 10000,
"channel_uuid": "74729f45-7f29-4868-9dc4-90e491e3c7d8",
"contact_id": 10000,
"contact_urn_id": 10000,
"created_on": "2021-11-09T14:03:30Z",
"direction": "O",
"error_count": 0,
"high_priority": false,
"id": %d,
"modified_on": %s,
"next_attempt": null,
"org_id": 1,
"queued_on": %s,
"sent_on": null,
"status": "Q",
"text": "Blast",
"tps_cost": 1,
"urn": "tel:+250700000001?id=10000",
"uuid": "%s"
}`, msg3.ID(), jsonx.MustMarshal(msg3.ModifiedOn()), jsonx.MustMarshal(msg3.QueuedOn()), msg3.UUID())), marshaled)
}`, msg3.ID(), msg3.UUID())), marshaled)
}

func TestQueueCourierMessages(t *testing.T) {
Expand Down

0 comments on commit 25dbd8e

Please sign in to comment.