Skip to content

Commit

Permalink
Merge pull request nyaruka#419 from Ilhasoft/fix/whatsapp-attachments…
Browse files Browse the repository at this point in the history
…-filename

fix whatsapp uploaded attachment file name
  • Loading branch information
rowanseymour authored Feb 17, 2022
2 parents dbe5d13 + 50a68d6 commit 1385e04
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion handlers/whatsapp/whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
if err != nil {
logrus.WithField("channel_uuid", msg.Channel().UUID().String()).WithError(err).Error("error while uploading media to whatsapp")
}
fileURL := mediaURL
if err == nil && mediaID != "" {
mediaURL = ""
}
Expand All @@ -605,7 +606,7 @@ func buildPayloads(msg courier.Msg, h *handler) ([]interface{}, []*courier.Chann
if attachmentCount == 0 && !isInteractiveMsg {
mediaPayload.Caption = msg.Text()
}
mediaPayload.Filename, err = utils.BasePathForURL(mediaURL)
mediaPayload.Filename, err = utils.BasePathForURL(fileURL)

// Logging error
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions handlers/whatsapp/whatsapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,49 @@ var mediaCacheSendTestCases = []ChannelSendTestCase{
},
SendPrep: setSendURL,
},
{
Label: "Document Upload OK",
Text: "document caption",
URN: "whatsapp:250788123123",
Status: "W", ExternalID: "157b5e14568e8",
Attachments: []string{"application/pdf:https://foo.bar/document2.pdf"},
Responses: map[MockedRequest]MockedResponse{
MockedRequest{
Method: "POST",
Path: "/v1/media",
Body: "media bytes",
}: MockedResponse{
Status: 200,
Body: `{ "media" : [{"id": "25c484d1-1283-4b94-988d-7276bdec4ef3"}] }`,
},
MockedRequest{
Method: "POST",
Path: "/v1/messages",
Body: `{"to":"250788123123","type":"document","document":{"id":"25c484d1-1283-4b94-988d-7276bdec4ef3","caption":"document caption","filename":"document2.pdf"}}`,
}: MockedResponse{
Status: 201,
Body: `{ "messages": [{"id": "157b5e14568e8"}] }`,
},
},
SendPrep: setSendURL,
},
{Label: "Cached Document",
Text: "document caption",
URN: "whatsapp:250788123123",
Status: "W", ExternalID: "157b5e14568e8",
Attachments: []string{"application/pdf:https://foo.bar/document2.pdf"},
Responses: map[MockedRequest]MockedResponse{
MockedRequest{
Method: "POST",
Path: "/v1/messages",
Body: `{"to":"250788123123","type":"document","document":{"id":"25c484d1-1283-4b94-988d-7276bdec4ef3","caption":"document caption","filename":"document2.pdf"}}`,
}: MockedResponse{
Status: 201,
Body: `{ "messages": [{"id": "157b5e14568e8"}] }`,
},
},
SendPrep: setSendURL,
},
}

var hsmSupportSendTestCases = []ChannelSendTestCase{
Expand Down

0 comments on commit 1385e04

Please sign in to comment.