From 2ac235a538716e6bb2a72f04384294cc92e9794c Mon Sep 17 00:00:00 2001 From: Norbert Kwizera Date: Sun, 7 Jan 2024 10:47:23 +0200 Subject: [PATCH] Fix sending bandwidth MMS without text --- handlers/bandwidth/handler.go | 5 +++++ handlers/bandwidth/handler_test.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/handlers/bandwidth/handler.go b/handlers/bandwidth/handler.go index 2441270f0..98e76bf95 100644 --- a/handlers/bandwidth/handler.go +++ b/handlers/bandwidth/handler.go @@ -199,7 +199,12 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, clog *courier.Ch msgParts := make([]string, 0) if msg.Text() != "" { msgParts = handlers.SplitMsgByChannel(msg.Channel(), msg.Text(), maxMsgLength) + } else { + if len(msg.Attachments()) > 0 { + msgParts = append(msgParts, "") + } } + for i, part := range msgParts { payload := &mtPayload{} payload.ApplicationID = applicationID diff --git a/handlers/bandwidth/handler_test.go b/handlers/bandwidth/handler_test.go index 5707ae0d2..76d96b682 100644 --- a/handlers/bandwidth/handler_test.go +++ b/handlers/bandwidth/handler_test.go @@ -293,6 +293,27 @@ var defaultSendTestCases = []OutgoingTestCase{ ExpectedExternalID: "55555", SendPrep: setSendURL, }, + { + Label: "Send Attachment no text", + MsgText: "", + MsgURN: "tel:+12067791234", + MsgAttachments: []string{"image/jpeg:https://foo.bar/image.jpg"}, + MockResponseBody: `{"id": "55555"}`, + MockResponseStatus: 200, + ExpectedRequests: []ExpectedRequest{ + { + Headers: map[string]string{ + "Content-Type": "application/json", + "Accept": "application/json", + "Authorization": "Basic dXNlcjE6cGFzczE=", + }, + Body: `{"applicationId":"application-id","to":["+12067791234"],"from":"2020","text":"","media":["https://foo.bar/image.jpg"]}`, + }, + }, + ExpectedMsgStatus: "W", + ExpectedExternalID: "55555", + SendPrep: setSendURL, + }, { Label: "No External ID", MsgText: "No External ID",