mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-30 18:47:51 +00:00 
			
		
		
		
	chore: Slack file upload changes (#10903)
The Slack `files.upload` API endpoint is deprecated and will stop functioning on March 11, 2025. In this PR, we have implemented the changes for the [new file upload](https://api.slack.com/messaging/files#uploading_files) method.
This commit is contained in:
		
							
								
								
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Gemfile
									
									
									
									
									
								
							| @@ -94,7 +94,7 @@ gem 'twitty', '~> 0.1.5' | |||||||
| # facebook client | # facebook client | ||||||
| gem 'koala' | gem 'koala' | ||||||
| # slack client | # slack client | ||||||
| gem 'slack-ruby-client', '~> 2.2.0' | gem 'slack-ruby-client', '~> 2.5.1' | ||||||
| # for dialogflow integrations | # for dialogflow integrations | ||||||
| gem 'google-cloud-dialogflow-v2', '>= 0.24.0' | gem 'google-cloud-dialogflow-v2', '>= 0.24.0' | ||||||
| gem 'grpc' | gem 'grpc' | ||||||
|   | |||||||
| @@ -272,7 +272,8 @@ GEM | |||||||
|       googleauth (~> 1.0) |       googleauth (~> 1.0) | ||||||
|       grpc (~> 1.36) |       grpc (~> 1.36) | ||||||
|     geocoder (1.8.1) |     geocoder (1.8.1) | ||||||
|     gli (2.21.1) |     gli (2.22.2) | ||||||
|  |       ostruct | ||||||
|     globalid (1.2.1) |     globalid (1.2.1) | ||||||
|       activesupport (>= 6.1) |       activesupport (>= 6.1) | ||||||
|     gmail_xoauth (0.4.3) |     gmail_xoauth (0.4.3) | ||||||
| @@ -537,6 +538,7 @@ GEM | |||||||
|     openssl (3.2.0) |     openssl (3.2.0) | ||||||
|     orm_adapter (0.5.0) |     orm_adapter (0.5.0) | ||||||
|     os (1.1.4) |     os (1.1.4) | ||||||
|  |     ostruct (0.6.1) | ||||||
|     parallel (1.23.0) |     parallel (1.23.0) | ||||||
|     parser (3.2.2.1) |     parser (3.2.2.1) | ||||||
|       ast (~> 2.4.1) |       ast (~> 2.4.1) | ||||||
| @@ -745,12 +747,13 @@ GEM | |||||||
|       json (>= 1.8, < 3) |       json (>= 1.8, < 3) | ||||||
|       simplecov-html (~> 0.10.0) |       simplecov-html (~> 0.10.0) | ||||||
|     simplecov-html (0.10.2) |     simplecov-html (0.10.2) | ||||||
|     slack-ruby-client (2.2.0) |     slack-ruby-client (2.5.1) | ||||||
|       faraday (>= 2.0) |       faraday (>= 2.0) | ||||||
|       faraday-mashify |       faraday-mashify | ||||||
|       faraday-multipart |       faraday-multipart | ||||||
|       gli |       gli | ||||||
|       hashie |       hashie | ||||||
|  |       logger | ||||||
|     snaky_hash (2.0.1) |     snaky_hash (2.0.1) | ||||||
|       hashie |       hashie | ||||||
|       version_gem (~> 1.1, >= 1.1.1) |       version_gem (~> 1.1, >= 1.1.1) | ||||||
| @@ -951,7 +954,7 @@ DEPENDENCIES | |||||||
|   sidekiq (>= 7.3.1) |   sidekiq (>= 7.3.1) | ||||||
|   sidekiq-cron (>= 1.12.0) |   sidekiq-cron (>= 1.12.0) | ||||||
|   simplecov (= 0.17.1) |   simplecov (= 0.17.1) | ||||||
|   slack-ruby-client (~> 2.2.0) |   slack-ruby-client (~> 2.5.1) | ||||||
|   spring |   spring | ||||||
|   spring-watcher-listen |   spring-watcher-listen | ||||||
|   squasher |   squasher | ||||||
|   | |||||||
| @@ -119,12 +119,14 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService | |||||||
|   def upload_file |   def upload_file | ||||||
|     return unless message.attachments.first.with_attached_file? |     return unless message.attachments.first.with_attached_file? | ||||||
|  |  | ||||||
|     result = slack_client.files_upload({ |     result = slack_client.files_upload_v2( | ||||||
|       channels: hook.reference_id, |       filename: message.attachments.first.file.filename, | ||||||
|  |       content: message.attachments.first.file.download, | ||||||
|       initial_comment: 'Attached File!', |       initial_comment: 'Attached File!', | ||||||
|       thread_ts: conversation.identifier |       thread_ts: conversation.identifier, | ||||||
|     }.merge(file_information)) |       channel_id: hook.reference_id | ||||||
|     Rails.logger.info(result) |     ) | ||||||
|  |     Rails.logger.info "slack_upload_result: #{result}" | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   def file_type |   def file_type | ||||||
|   | |||||||
| @@ -162,15 +162,13 @@ describe Integrations::Slack::SendOnSlackService do | |||||||
|         attachment = message.attachments.new(account_id: message.account_id, file_type: :image) |         attachment = message.attachments.new(account_id: message.account_id, file_type: :image) | ||||||
|         attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png') |         attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png') | ||||||
|  |  | ||||||
|         expect(slack_client).to receive(:files_upload).with(hash_including( |         expect(slack_client).to receive(:files_upload_v2).with( | ||||||
|                                                               channels: hook.reference_id, |           filename: attachment.file.filename, | ||||||
|                                                               thread_ts: conversation.identifier, |           content: anything, | ||||||
|                                                               initial_comment: 'Attached File!', |           channel_id: hook.reference_id, | ||||||
|                                                               filetype: 'png', |           thread_ts: conversation.identifier, | ||||||
|                                                               content: anything, |           initial_comment: 'Attached File!' | ||||||
|                                                               filename: attachment.file.filename, |         ).and_return(file_attachment) | ||||||
|                                                               title: attachment.file.filename |  | ||||||
|                                                             )).and_return(file_attachment) |  | ||||||
|  |  | ||||||
|         message.save! |         message.save! | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Muhsin Keloth
					Muhsin Keloth