Skip to content
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

Use response_to_external_id instead of response_to_id #389

Merged
merged 1 commit into from
Dec 1, 2021
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.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (b *backend) IsMsgLoop(ctx context.Context, msg courier.Msg) (bool, error)
m := msg.(*DBMsg)

// things that aren't replies can't be loops, neither do we count retries
if m.ResponseToID_ == courier.NilMsgID || m.ErrorCount_ > 0 {
if m.ResponseToExternalID_ == "" || m.ErrorCount_ > 0 {
return false, nil
}

Expand Down
8 changes: 2 additions & 6 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func (ts *BackendTestSuite) TestMsgUnmarshal() {
"sent_on": null,
"high_priority": true,
"channel_id": 11,
"response_to_id": 15,
"response_to_external_id": "external-id",
"external_id": null,
"is_resend": true,
Expand All @@ -137,7 +136,6 @@ func (ts *BackendTestSuite) TestMsgUnmarshal() {
ts.Equal(msg.ExternalID(), "")
ts.Equal([]string{"Yes", "No"}, msg.QuickReplies())
ts.Equal("event", msg.Topic())
ts.Equal(courier.NewMsgID(15), msg.ResponseToID())
ts.Equal("external-id", msg.ResponseToExternalID())
ts.True(msg.HighPriority())
ts.True(msg.IsResend())
Expand All @@ -162,8 +160,7 @@ func (ts *BackendTestSuite) TestMsgUnmarshal() {
"sent_on": null,
"high_priority": true,
"channel_id": 11,
"response_to_id": null,
"response_to_external_id": "",
"response_to_external_id": null,
"external_id": null,
"metadata": null
}`
Expand All @@ -173,7 +170,6 @@ func (ts *BackendTestSuite) TestMsgUnmarshal() {
ts.NoError(err)
ts.Equal([]string{}, msg.QuickReplies())
ts.Equal("", msg.Topic())
ts.Equal(courier.NilMsgID, msg.ResponseToID())
ts.Equal("", msg.ResponseToExternalID())
ts.False(msg.IsResend())
}
Expand Down Expand Up @@ -756,7 +752,7 @@ func (ts *BackendTestSuite) TestLoop() {
ctx := context.Background()
dbMsg := readMsgFromDB(ts.b, courier.NewMsgID(10000))

dbMsg.ResponseToID_ = courier.MsgID(5)
dbMsg.ResponseToExternalID_ = "65474"

loop, err := ts.b.IsMsgLoop(ctx, dbMsg)
ts.NoError(err)
Expand Down
2 changes: 0 additions & 2 deletions backends/rapidpro/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ type DBMsg struct {
Text_ string `json:"text" db:"text"`
Attachments_ pq.StringArray `json:"attachments" db:"attachments"`
ExternalID_ null.String `json:"external_id" db:"external_id"`
ResponseToID_ courier.MsgID `json:"response_to_id" db:"response_to_id"`
ResponseToExternalID_ string `json:"response_to_external_id"`
IsResend_ bool `json:"is_resend,omitempty"`
Metadata_ json.RawMessage `json:"metadata" db:"metadata"`
Expand Down Expand Up @@ -534,7 +533,6 @@ func (m *DBMsg) ContactName() string { return m.ContactName_ }
func (m *DBMsg) HighPriority() bool { return m.HighPriority_ }
func (m *DBMsg) ReceivedOn() *time.Time { return m.SentOn_ }
func (m *DBMsg) SentOn() *time.Time { return m.SentOn_ }
func (m *DBMsg) ResponseToID() courier.MsgID { return m.ResponseToID_ }
func (m *DBMsg) ResponseToExternalID() string { return m.ResponseToExternalID_ }
func (m *DBMsg) IsResend() bool { return m.IsResend_ }

Expand Down
2 changes: 0 additions & 2 deletions handlers/chikka/chikka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ var defaultSendTestCases = []ChannelSendTestCase{
{Label: "Plain Reply",
Text: "Simple Message", URN: "tel:+63911231234",
Status: "W",
ResponseToID: 5,
ResponseToExternalID: "external-id",
ResponseBody: "Success", ResponseStatus: 200,
PostParams: map[string]string{
Expand All @@ -88,7 +87,6 @@ var defaultSendTestCases = []ChannelSendTestCase{
SendPrep: setSendURL},
{Label: "Failed Reply use Send",
Text: "Simple Message", URN: "tel:+63911231234",
ResponseToID: 5,
ResponseToExternalID: "external-id",
ResponseBody: `{"status":400,"message":"BAD REQUEST","description":"Invalid\\/Used Request ID"}`,
ResponseStatus: 400,
Expand Down
2 changes: 1 addition & 1 deletion handlers/facebook/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
payload := mtPayload{}

// set our message type
if msg.ResponseToID() != courier.NilMsgID {
if msg.ResponseToExternalID() != "" {
payload.MessagingType = "RESPONSE"
} else if topic != "" {
payload.MessagingType = "MESSAGE_TAG"
Expand Down
2 changes: 1 addition & 1 deletion handlers/facebook/facebook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ var defaultSendTestCases = []ChannelSendTestCase{
SendPrep: setSendURL},
{Label: "Plain Response",
Text: "Simple Message", URN: "facebook:12345",
Status: "W", ExternalID: "mid.133", ResponseToID: 23526,
Status: "W", ExternalID: "mid.133", ResponseToExternalID: "23526",
ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200,
RequestBody: `{"messaging_type":"RESPONSE","recipient":{"id":"12345"},"message":{"text":"Simple Message"}}`,
SendPrep: setSendURL},
Expand Down
2 changes: 1 addition & 1 deletion handlers/facebookapp/facebookapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (h *handler) SendMsg(ctx context.Context, msg courier.Msg) (courier.MsgStat
payload := mtPayload{}

// set our message type
if msg.ResponseToID() != courier.NilMsgID {
if msg.ResponseToExternalID() != "" {
payload.MessagingType = "RESPONSE"
} else if topic != "" {
payload.MessagingType = "MESSAGE_TAG"
Expand Down
2 changes: 1 addition & 1 deletion handlers/facebookapp/facebookapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ var defaultSendTestCases = []ChannelSendTestCase{
SendPrep: setSendURL},
{Label: "Plain Response",
Text: "Simple Message", URN: "facebook:12345",
Status: "W", ExternalID: "mid.133", ResponseToID: 23526,
Status: "W", ExternalID: "mid.133", ResponseToExternalID: "23526",
ResponseBody: `{"message_id": "mid.133"}`, ResponseStatus: 200,
RequestBody: `{"messaging_type":"RESPONSE","recipient":{"id":"12345"},"message":{"text":"Simple Message"}}`,
SendPrep: setSendURL},
Expand Down
3 changes: 1 addition & 2 deletions handlers/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type ChannelSendTestCase struct {
QuickReplies []string
Topic string
HighPriority bool
ResponseToID int64
ResponseToExternalID string
Metadata json.RawMessage

Expand Down Expand Up @@ -221,7 +220,7 @@ func RunChannelSendTestCases(t *testing.T, channel courier.Channel, handler cour
t.Run(testCase.Label, func(t *testing.T) {
require := require.New(t)

msg := mb.NewOutgoingMsg(channel, courier.NewMsgID(10), urns.URN(testCase.URN), testCase.Text, testCase.HighPriority, testCase.QuickReplies, testCase.Topic, testCase.ResponseToID, testCase.ResponseToExternalID)
msg := mb.NewOutgoingMsg(channel, courier.NewMsgID(10), urns.URN(testCase.URN), testCase.Text, testCase.HighPriority, testCase.QuickReplies, testCase.Topic, testCase.ResponseToExternalID)

for _, a := range testCase.Attachments {
msg.WithAttachment(a)
Expand Down
1 change: 0 additions & 1 deletion msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ type Msg interface {
QuickReplies() []string
Topic() string
Metadata() json.RawMessage
ResponseToID() MsgID
ResponseToExternalID() string
IsResend() bool

Expand Down
11 changes: 2 additions & 9 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,8 @@ func (mb *MockBackend) NewIncomingMsg(channel Channel, urn urns.URN, text string
}

// NewOutgoingMsg creates a new outgoing message from the given params
func (mb *MockBackend) NewOutgoingMsg(channel Channel, id MsgID, urn urns.URN, text string, highPriority bool, quickReplies []string, topic string, responseToID int64, responseToExternalID string) Msg {
msgResponseToID := NilMsgID
if responseToID != 0 {
msgResponseToID = NewMsgID(responseToID)
}

return &mockMsg{channel: channel, id: id, urn: urn, text: text, highPriority: highPriority, quickReplies: quickReplies, topic: topic, responseToID: msgResponseToID, responseToExternalID: responseToExternalID}
func (mb *MockBackend) NewOutgoingMsg(channel Channel, id MsgID, urn urns.URN, text string, highPriority bool, quickReplies []string, topic string, responseToExternalID string) Msg {
return &mockMsg{channel: channel, id: id, urn: urn, text: text, highPriority: highPriority, quickReplies: quickReplies, topic: topic, responseToExternalID: responseToExternalID}
}

// PushOutgoingMsg is a test method to add a message to our queue of messages to send
Expand Down Expand Up @@ -568,7 +563,6 @@ type mockMsg struct {
highPriority bool
quickReplies []string
topic string
responseToID MsgID
responseToExternalID string
metadata json.RawMessage
alreadyWritten bool
Expand All @@ -594,7 +588,6 @@ func (m *mockMsg) ContactName() string { return m.contactName }
func (m *mockMsg) HighPriority() bool { return m.highPriority }
func (m *mockMsg) QuickReplies() []string { return m.quickReplies }
func (m *mockMsg) Topic() string { return m.topic }
func (m *mockMsg) ResponseToID() MsgID { return m.responseToID }
func (m *mockMsg) ResponseToExternalID() string { return m.responseToExternalID }
func (m *mockMsg) Metadata() json.RawMessage { return m.metadata }
func (m *mockMsg) IsResend() bool { return m.isResend }
Expand Down