Fix: slack repeated callback event message for attached files (#4610)

This commit is contained in:
Tejaswini Chile 2022-05-09 19:18:30 +05:30 committed by GitHub
parent 5ce29a7beb
commit 0eeab8c56c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View file

@ -35,9 +35,9 @@ class Integrations::Slack::IncomingMessageBuilder
def supported_message? def supported_message?
if message.present? if message.present?
SUPPORTED_MESSAGE_TYPES.include?(message[:type]) SUPPORTED_MESSAGE_TYPES.include?(message[:type]) && !attached_file_message?
else else
params.dig(:event, :files).any? params[:event][:files].any? && !attached_file_message?
end end
end end
@ -135,4 +135,12 @@ class Integrations::Slack::IncomingMessageBuilder
:file :file
end end
end end
# Ignoring the changes added here https://github.com/chatwoot/chatwoot/blob/5b5a6d89c0cf7f3148a1439d6fcd847784a79b94/lib/integrations/slack/send_on_slack_service.rb#L69
# This make sure 'Attached File!' comment is not visible on CW dashboard.
# This is showing because of https://github.com/chatwoot/chatwoot/pull/4494/commits/07a1c0da1e522d76e37b5f0cecdb4613389ab9b6 change.
# As now we consider the postback message with event[:files]
def attached_file_message?
params[:event][:text] == 'Attached File!'
end
end end

View file

@ -71,6 +71,18 @@ describe Integrations::Slack::IncomingMessageBuilder do
expect(conversation.messages.last.content).to eql('this is test https://chatwoot.com Hey @Sojan Test again') expect(conversation.messages.last.content).to eql('this is test https://chatwoot.com Hey @Sojan Test again')
expect(conversation.messages.last.attachments).to be_any expect(conversation.messages.last.attachments).to be_any
end end
it 'ignore message if it is postback of CW attachment message' do
expect(hook).not_to eq nil
messages_count = conversation.messages.count
message_with_attachments[:event][:text] = 'Attached File!'
builder = described_class.new(message_with_attachments)
allow(builder).to receive(:sender).and_return(nil)
builder.perform
expect(conversation.messages.count).to eql(messages_count)
end
end end
end end
end end