From 04194e7247715d53565de8e9c44b3e338c22eca8 Mon Sep 17 00:00:00 2001 From: Shivam Chahar Date: Thu, 28 Apr 2022 21:02:17 +0530 Subject: [PATCH] Fix: attachment name for incoming messages Use original_filename to get the name of the file attached to the message. Had to add the message_type method to the WhatsApp/incoming_message_service due to the Assignment Branch Condition linter error for the attach_files method. Fixes #4183 --- app/services/sms/incoming_message_service.rb | 2 +- app/services/telegram/incoming_message_service.rb | 2 +- app/services/whatsapp/incoming_message_service.rb | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/services/sms/incoming_message_service.rb b/app/services/sms/incoming_message_service.rb index eb0b5512b..a21f76b58 100644 --- a/app/services/sms/incoming_message_service.rb +++ b/app/services/sms/incoming_message_service.rb @@ -87,7 +87,7 @@ class Sms::IncomingMessageService file_type: file_type(attachment_file.content_type), file: { io: attachment_file, - filename: attachment_file, + filename: attachment_file.original_filename, content_type: attachment_file.content_type } ) diff --git a/app/services/telegram/incoming_message_service.rb b/app/services/telegram/incoming_message_service.rb index 1647623be..7ff7a6155 100644 --- a/app/services/telegram/incoming_message_service.rb +++ b/app/services/telegram/incoming_message_service.rb @@ -105,7 +105,7 @@ class Telegram::IncomingMessageService file_type: file_content_type, file: { io: attachment_file, - filename: attachment_file, + filename: attachment_file.original_filename, content_type: attachment_file.content_type } ) diff --git a/app/services/whatsapp/incoming_message_service.rb b/app/services/whatsapp/incoming_message_service.rb index 1a750b41a..c96e6e771 100644 --- a/app/services/whatsapp/incoming_message_service.rb +++ b/app/services/whatsapp/incoming_message_service.rb @@ -77,7 +77,6 @@ class Whatsapp::IncomingMessageService end def attach_files - message_type = params[:messages].first[:type] return if %w[text button interactive].include?(message_type) attachment_payload = params[:messages].first[message_type.to_sym] @@ -89,9 +88,13 @@ class Whatsapp::IncomingMessageService file_type: file_content_type(message_type), file: { io: attachment_file, - filename: attachment_file, + filename: attachment_file.original_filename, content_type: attachment_file.content_type } ) end + + def message_type + params[:messages].first[:type] + end end