mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 02:57:57 +00:00 
			
		
		
		
	fix: Handle video file types in Slack file shares (#12630)
Fixes https://linear.app/chatwoot/issue/CW-5752/fix-nomethoderror-when-processing-video-files-in-slack-integration #### Problem When users shared video files (like MP4) through Slack, the `file_type` method in `SlackMessageHelper` would return `nil` for unsupported file types. This caused a `NoMethodError (undefined method 'to_sym' for nil)` when the attachment was being processed, as the system expected a symbol value for the `file_type` attribute. #### Solution - Added video file type support in the `file_type` method case statement - Added `else` clause to default unknown file types to `:file` instead of returning `nil` - This ensures `file_type` always returns a symbol, preventing the `to_sym` error
This commit is contained in:
		| @@ -70,7 +70,9 @@ module Integrations::Slack::SlackMessageHelper | |||||||
|     case attachment[:filetype] |     case attachment[:filetype] | ||||||
|     when 'png', 'jpeg', 'gif', 'bmp', 'tiff', 'jpg' |     when 'png', 'jpeg', 'gif', 'bmp', 'tiff', 'jpg' | ||||||
|       :image |       :image | ||||||
|     when 'pdf' |     when 'mp4', 'avi', 'mov', 'wmv', 'flv', 'webm' | ||||||
|  |       :video | ||||||
|  |     else | ||||||
|       :file |       :file | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|   | |||||||
| @@ -157,6 +157,19 @@ describe Integrations::Slack::IncomingMessageBuilder do | |||||||
|  |  | ||||||
|         expect(conversation.messages.count).to eql(messages_count) |         expect(conversation.messages.count).to eql(messages_count) | ||||||
|       end |       end | ||||||
|  |  | ||||||
|  |       it 'handles different file types correctly' do | ||||||
|  |         expect(hook).not_to be_nil | ||||||
|  |         video_attachment_params = message_with_attachments.deep_dup | ||||||
|  |         video_attachment_params[:event][:files][0][:filetype] = 'mp4' | ||||||
|  |         video_attachment_params[:event][:files][0][:mimetype] = 'video/mp4' | ||||||
|  |  | ||||||
|  |         builder = described_class.new(video_attachment_params) | ||||||
|  |         allow(builder).to receive(:sender).and_return(nil) | ||||||
|  |  | ||||||
|  |         expect { builder.perform }.not_to raise_error | ||||||
|  |         expect(conversation.messages.last.attachments).to be_any | ||||||
|  |       end | ||||||
|     end |     end | ||||||
|  |  | ||||||
|     context 'when link shared' do |     context 'when link shared' do | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Muhsin Keloth
					Muhsin Keloth