fix: Handle Facebook reel attachment type (#13691)

Fixes https://linear.app/chatwoot/issue/PLA-96/argumenterror-reel-is-not-a-valid-file-type-argumenterror
Fixes a crash in `when a user shares a Facebook reel via Messenger.
Facebook sends these attachments with `type: "reel"`, which isn't a
valid `file_type` enum value on the Attachment model (only `ig_reel`
exists, matching Instagram's format).

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Muhsin Keloth
2026-03-06 08:49:41 +04:00
committed by GitHub
parent 059506b1db
commit 598ece9a2d
4 changed files with 107 additions and 5 deletions

View File

@@ -89,6 +89,57 @@ describe Messages::Facebook::MessageBuilder do
expect(message.content_attributes['external_echo']).to be true
end
context 'when message contains a reel attachment' do
let(:reel_message_object) do
{
messaging: {
sender: { id: '3383290475046708' },
recipient: { id: facebook_channel.page_id },
timestamp: 1_772_452_164_516,
message: {
mid: 'm_reel_test',
attachments: [
{
type: 'reel',
payload: {
url: 'https://www.facebook.com/reel/123456',
title: 'Test Reel Title',
reel_video_id: 123_456
}
}
]
}
}
}.to_json
end
let(:reel_message) { Integrations::Facebook::MessageParser.new(reel_message_object) }
before do
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
allow(fb_object).to receive(:get_object).and_return(
{ first_name: 'Jane', last_name: 'Dae', profile_pic: 'https://chatwoot-assets.local/sample.png' }.with_indifferent_access
)
end
it 'creates an ig_reel attachment without downloading the file' do
expect(Down).not_to receive(:download)
described_class.new(reel_message, facebook_channel.inbox).perform
message = facebook_channel.inbox.messages.find_by(source_id: 'm_reel_test')
expect(message).to be_present
expect(message.attachments.first.file_type).to eq('ig_reel')
expect(message.attachments.first.external_url).to eq('https://www.facebook.com/reel/123456')
expect(message.attachments.first.file.attached?).to be false
end
it 'sets the reel URL as message content' do
described_class.new(reel_message, facebook_channel.inbox).perform
message = facebook_channel.inbox.messages.find_by(source_id: 'm_reel_test')
expect(message.content).to eq('https://www.facebook.com/reel/123456')
end
end
context 'when lock to single conversation' do
subject(:mocked_message_builder) do
described_class.new(mocked_incoming_fb_text_message, facebook_channel.inbox).perform