diff --git a/handlers/facebook_legacy/handler.go b/handlers/facebook_legacy/handler.go index 47d6a10ec..f929901e3 100644 --- a/handlers/facebook_legacy/handler.go +++ b/handlers/facebook_legacy/handler.go @@ -372,7 +372,7 @@ func (h *handler) receiveEvents(ctx context.Context, channel courier.Channel, w attachmentURLs = append(attachmentURLs, fmt.Sprintf("geo:%f,%f", att.Payload.Coordinates.Lat, att.Payload.Coordinates.Long)) } - if att.Payload != nil && att.Payload.URL != "" { + if att.Payload != nil && att.Payload.URL != "" && att.Type != "fallback" && strings.HasPrefix(att.Payload.URL, "http") { attachmentURLs = append(attachmentURLs, att.Payload.URL) } @@ -384,6 +384,11 @@ func (h *handler) receiveEvents(ctx context.Context, channel courier.Channel, w text = stickerText } + // if we have no text or accepted attachments, don't create a message + if text == "" && len(attachmentURLs) == 0 { + continue + } + // create our message event := h.Backend().NewIncomingMsg(channel, urn, text, msg.Message.MID, clog).WithReceivedOn(date) diff --git a/handlers/facebook_legacy/handler_test.go b/handlers/facebook_legacy/handler_test.go index e17973805..a6fd0b559 100644 --- a/handlers/facebook_legacy/handler_test.go +++ b/handlers/facebook_legacy/handler_test.go @@ -134,6 +134,59 @@ var attachment = `{ }] }` +var attachmentReel = `{ + "object":"page", + "entry": [{ + "id": "208685479508187", + "messaging": [{ + "message": { + "mid": "external_id", + "attachments":[{ + "type":"ig_reel", + "payload":{ + "url":"\/reel\/1833422637182325\/" + } + }] + }, + "recipient": { + "id": "1234" + }, + "sender": { + "id": "5678" + }, + "timestamp": 1459991487970 + }], + "time": 1459991487970 + }] +}` + +var attachmentFallback = `{ + "object":"page", + "entry": [{ + "id": "208685479508187", + "messaging": [{ + "message": { + "mid": "external_id", + "attachments":[{ + "type":"fallback", + "payload":{ + "url":"https://image-url/foo.png", + "title": "Foo" + } + }] + }, + "recipient": { + "id": "1234" + }, + "sender": { + "id": "5678" + }, + "timestamp": 1459991487970 + }], + "time": 1459991487970 + }] +}` + var locationAttachment = `{ "object":"page", "entry": [{ @@ -455,6 +508,22 @@ var testCases = []IncomingTestCase{ ExpectedExternalID: "external_id", ExpectedDate: time.Date(2016, 4, 7, 1, 11, 27, 970000000, time.UTC), }, + { + Label: "Receive unsupported reel attachment", + URL: receiveURL, + Data: attachmentReel, + ExpectedRespStatus: 200, + ExpectedBodyContains: "Handled", + ExpectedEvents: []ExpectedEvent{}, + }, + { + Label: "Receive fallback attachment ignored", + URL: receiveURL, + Data: attachmentFallback, + ExpectedRespStatus: 200, + ExpectedBodyContains: "Handled", + ExpectedEvents: []ExpectedEvent{}, + }, { Label: "Receive Location", URL: receiveURL,