feat: Add support for multiple attachments in Slack (#11958)

This commit is contained in:
Muhsin Keloth
2025-07-17 09:38:46 +05:30
committed by GitHub
parent 64ba23688b
commit 99ec18c95b
2 changed files with 71 additions and 10 deletions

View File

@@ -121,16 +121,22 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
end
def upload_file
return unless message.attachments.first.with_attached_file?
message.attachments.each do |attachment|
next unless attachment.with_attached_file?
result = slack_client.files_upload_v2(
filename: message.attachments.first.file.filename,
content: message.attachments.first.file.download,
initial_comment: 'Attached File!',
thread_ts: conversation.identifier,
channel_id: hook.reference_id
)
Rails.logger.info "slack_upload_result: #{result}"
begin
result = slack_client.files_upload_v2(
filename: attachment.file.filename.to_s,
content: attachment.file.download,
initial_comment: 'Attached File!',
thread_ts: conversation.identifier,
channel_id: hook.reference_id
)
Rails.logger.info "slack_upload_result: #{result}"
rescue Slack::Web::Api::Errors::SlackError => e
Rails.logger.error "Failed to upload file #{attachment.file.filename}: #{e.message}"
end
end
end
def file_type