From 4974987a4e7436037dd4882ac880084d9731e5b0 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Fri, 23 Feb 2024 09:58:17 -0500 Subject: [PATCH] Minor cleanup --- handlers/m3tech/handler_test.go | 15 ++++++++++----- handlers/meta/handlers.go | 10 ++++++---- handlers/mtarget/handler.go | 1 - handlers/playmobile/handler_test.go | 12 ++++++++---- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/handlers/m3tech/handler_test.go b/handlers/m3tech/handler_test.go index 2048b8fdb..a1ecee642 100644 --- a/handlers/m3tech/handler_test.go +++ b/handlers/m3tech/handler_test.go @@ -49,7 +49,8 @@ func BenchmarkHandler(b *testing.B) { } var defaultSendTestCases = []OutgoingTestCase{ - {Label: "Plain Send", + { + Label: "Plain Send", MsgText: "Simple Message", MsgURN: "tel:+250788383383", MockResponses: map[string][]*httpx.MockResponse{ @@ -73,7 +74,8 @@ var defaultSendTestCases = []OutgoingTestCase{ }, }}, }, - {Label: "Unicode Send", + { + Label: "Unicode Send", MsgText: "☺", MsgURN: "tel:+250788383383", MockResponses: map[string][]*httpx.MockResponse{ @@ -97,7 +99,8 @@ var defaultSendTestCases = []OutgoingTestCase{ }, }}, }, - {Label: "Smart Encoding", + { + Label: "Smart Encoding", MsgText: "Fancy “Smart” Quotes", MsgURN: "tel:+250788383383", MockResponses: map[string][]*httpx.MockResponse{ @@ -121,7 +124,8 @@ var defaultSendTestCases = []OutgoingTestCase{ }, }}, }, - {Label: "Send Attachment", + { + Label: "Send Attachment", MsgText: "My pic!", MsgURN: "tel:+250788383383", MsgAttachments: []string{"image/jpeg:https://foo.bar/image.jpg"}, @@ -146,7 +150,8 @@ var defaultSendTestCases = []OutgoingTestCase{ }, }}, }, - {Label: "Error Sending", + { + Label: "Error Sending", MsgText: "Error Sending", MsgURN: "tel:+250788383383", MockResponses: map[string][]*httpx.MockResponse{ diff --git a/handlers/meta/handlers.go b/handlers/meta/handlers.go index 903e4cc03..bdd985e3d 100644 --- a/handlers/meta/handlers.go +++ b/handlers/meta/handlers.go @@ -826,9 +826,10 @@ func (h *handler) sendWhatsAppMsg(ctx context.Context, msg courier.MsgOut, res * } else { if len(qrs) > 0 { payload.Type = "interactive" + + // if we have more than 10 quick replies, truncate and add channel error if len(qrs) > 10 { clog.Error(courier.NewChannelError("", "", "too many quick replies WAC supports only up to 10 quick replies")) - // limit to the first 10 qrs = qrs[:10] } @@ -852,7 +853,7 @@ func (h *handler) sendWhatsAppMsg(ctx context.Context, msg courier.MsgOut, res * Buttons []whatsapp.Button "json:\"buttons,omitempty\"" }{Buttons: btns} payload.Interactive = &interactive - } else if len(qrs) <= 10 { + } else { interactive := whatsapp.Interactive{Type: "list", Body: struct { Text string "json:\"text\"" }{Text: msgParts[i-len(msg.Attachments())]}} @@ -923,9 +924,10 @@ func (h *handler) sendWhatsAppMsg(ctx context.Context, msg courier.MsgOut, res * } else { if len(qrs) > 0 { payload.Type = "interactive" + + // if we have more than 10 quick replies, truncate and add channel error if len(qrs) > 10 { clog.Error(courier.NewChannelError("", "", "too many quick replies WAC supports only up to 10 quick replies")) - // limit to the first 10 qrs = qrs[:10] } @@ -1008,7 +1010,7 @@ func (h *handler) sendWhatsAppMsg(ctx context.Context, msg courier.MsgOut, res * }{Buttons: btns} payload.Interactive = &interactive - } else if len(qrs) <= 10 { + } else { interactive := whatsapp.Interactive{Type: "list", Body: struct { Text string "json:\"text\"" }{Text: msgParts[i-len(msg.Attachments())]}} diff --git a/handlers/mtarget/handler.go b/handlers/mtarget/handler.go index ed0b6a173..5acab7069 100644 --- a/handlers/mtarget/handler.go +++ b/handlers/mtarget/handler.go @@ -192,7 +192,6 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, res *courier.Sen code, _ := jsonparser.GetString(respBody, "results", "[0]", "code") externalID, _ := jsonparser.GetString(respBody, "results", "[0]", "ticket") if code == "0" && externalID != "" { - // all went well, set ourselves to wired res.AddExternalID(externalID) } else { reason, _ := jsonparser.GetString(respBody, "results", "[0]", "reason") diff --git a/handlers/playmobile/handler_test.go b/handlers/playmobile/handler_test.go index 8e685566c..e5f017ca1 100644 --- a/handlers/playmobile/handler_test.go +++ b/handlers/playmobile/handler_test.go @@ -128,7 +128,8 @@ func BenchmarkHandler(b *testing.B) { } var defaultSendTestCases = []OutgoingTestCase{ - {Label: "Plain Send", + { + Label: "Plain Send", MsgText: "Simple Message", MsgURN: "tel:99999999999", MockResponses: map[string][]*httpx.MockResponse{ @@ -140,7 +141,8 @@ var defaultSendTestCases = []OutgoingTestCase{ Body: `{"messages":[{"recipient":"99999999999","message-id":"10","sms":{"originator":"1122","content":{"text":"Simple Message"}}}]}`, }}, }, - {Label: "Long Send", + { + Label: "Long Send", MsgText: "This is a longer message than 640 characters and will cause us to split it into two separate parts, isn't that right but it is even longer than before I say, This is a longer message than 640 characters and will cause us to split it into two separate parts, isn't that right but it is even longer than before I say, This is a longer message than 640 characters and will cause us to split it into two separate parts, isn't that right but it is even longer than before I say, This is a longer message than 640 characters and will cause us to split it into two separate parts, isn't that right but it is even longer than before I say, now, I need to keep adding more things to make it work", MsgURN: "tel:99999999999", MockResponses: map[string][]*httpx.MockResponse{ @@ -158,7 +160,8 @@ var defaultSendTestCases = []OutgoingTestCase{ }, }, }, - {Label: "Send Attachment", + { + Label: "Send Attachment", MsgText: "My pic!", MsgURN: "tel:+18686846481", MsgAttachments: []string{"image/jpeg:https://foo.bar/image.jpg"}, @@ -168,7 +171,8 @@ var defaultSendTestCases = []OutgoingTestCase{ }, }, }, - {Label: "Error sending", + { + Label: "Error sending", MsgText: "Error Sending", MsgURN: "tel:+250788383383", MockResponses: map[string][]*httpx.MockResponse{