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

@@ -155,6 +155,30 @@ RSpec.describe Attachment do
end
end
describe 'push_event_data for ig_reel attachments' do
it 'returns external_url as data_url when no file is attached' do
attachment = message.attachments.create!(
account_id: message.account_id,
file_type: :ig_reel,
external_url: 'https://www.facebook.com/reel/123456'
)
event_data = attachment.push_event_data
expect(event_data[:data_url]).to eq('https://www.facebook.com/reel/123456')
expect(event_data[:thumb_url]).to eq('')
end
it 'returns file_url as data_url when file is attached' do
attachment = message.attachments.new(account_id: message.account_id, file_type: :ig_reel,
external_url: 'https://www.instagram.com/reel/123')
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
attachment.save!
event_data = attachment.push_event_data
expect(event_data[:data_url]).to be_present
end
end
describe 'push_event_data for embed attachments' do
it 'returns external url as data_url' do
attachment = message.attachments.create!(account_id: message.account_id, file_type: :embed, external_url: 'https://example.com/embed')