Skip to content

Commit

Permalink
Merge pull request #793 from nyaruka/fix-FB-ignore-reel
Browse files Browse the repository at this point in the history
Ignore reels as attachments on FB channels
  • Loading branch information
norkans7 authored Oct 21, 2024
2 parents 615b043 + 0680895 commit 252745b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
7 changes: 6 additions & 1 deletion handlers/facebook_legacy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)

Expand Down
69 changes: 69 additions & 0 deletions handlers/facebook_legacy/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": [{
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 252745b

Please sign in to comment.