fix: avoid Slack file upload API for fallback messages (#10461)
Skip calling the Slack file upload API for message types such as fallback (e.g., Facebook and location messages) that lack actual file data in attachments. This prevents unnecessary API calls and resolves a Sentry error currently occurring in production. fixes: https://github.com/chatwoot/chatwoot/issues/10460
This commit is contained in:
@@ -180,6 +180,28 @@ describe Integrations::Slack::SendOnSlackService do
|
||||
expect(message.attachments).to be_any
|
||||
end
|
||||
|
||||
it 'will not call file_upload if attachment does not have a file (e.g facebook - fallback type)' do
|
||||
expect(slack_client).to receive(:chat_postMessage).with(
|
||||
channel: hook.reference_id,
|
||||
text: message.content,
|
||||
username: "#{message.sender.name} (Contact)",
|
||||
thread_ts: conversation.identifier,
|
||||
icon_url: anything,
|
||||
unfurl_links: true
|
||||
).and_return(slack_message)
|
||||
|
||||
message.attachments.new(account_id: message.account_id, file_type: :fallback)
|
||||
|
||||
expect(slack_client).not_to receive(:files_upload)
|
||||
|
||||
message.save!
|
||||
|
||||
builder.perform
|
||||
|
||||
expect(message.external_source_id_slack).to eq 'cw-origin-6789.12345'
|
||||
expect(message.attachments).to be_any
|
||||
end
|
||||
|
||||
it 'sent a template message on slack' do
|
||||
builder = described_class.new(message: template_message, hook: hook)
|
||||
allow(builder).to receive(:slack_client).and_return(slack_client)
|
||||
|
||||
Reference in New Issue
Block a user