Skip to content

Commit

Permalink
fix: Add a check for thread_ts (chatwoot#1389)
Browse files Browse the repository at this point in the history
- If no thread timestamp is available, ignore the message
- Add specs to cover the case
  • Loading branch information
Pranav Raj S authored Nov 9, 2020
1 parent 7718cf7 commit 2babfd6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/integrations/slack/incoming_message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ def hook_verification?
params[:type] == 'url_verification'
end

def thread_timestamp_available?
params[:event][:thread_ts].present?
end

def create_message?
supported_message? && integration_hook
thread_timestamp_available? && supported_message? && integration_hook
end

def message
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/integrations/slack/incoming_message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe Integrations::Slack::IncomingMessageBuilder do
let(:account) { create(:account) }
let(:message_params) { slack_message_stub }
let(:message_without_thread_ts) { slack_message_stub_without_thread_ts }
let(:verification_params) { slack_url_verification_stub }

let!(:hook) { create(:integrations_hook, account: account, reference_id: message_params[:event][:channel]) }
Expand All @@ -18,6 +19,13 @@
end

context 'when message creation' do
it 'doesnot create message if thread info is missing' do
messages_count = conversation.messages.count
builder = described_class.new(message_without_thread_ts)
builder.perform
expect(conversation.messages.count).to eql(messages_count)
end

it 'creates message' do
expect(hook).not_to eq nil
messages_count = conversation.messages.count
Expand Down
27 changes: 25 additions & 2 deletions spec/support/slack_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,30 @@ def slack_message_stub
}
end

def slack_message_stub_without_thread_ts
{
"token": '[FILTERED]',
"team_id": '',
"api_app_id": '',
"event": {
"type": 'message',
"client_msg_id": 'ffc6e64e-6f0c-4a3d-b594-faa6b44e48ab',
"text": 'this is test',
"user": 'ULYPAKE5S',
"ts": '1588623033.006000',
"team": 'TLST3048H'
},
"type": 'event_callback',
"event_id": '',
"event_time": 1_588_623_033,
"authed_users": '[FILTERED]',
"webhook": {}
}
end

def message_event
{ "client_msg_id": 'ffc6e64e-6f0c-4a3d-b594-faa6b44e48ab',
{
"client_msg_id": 'ffc6e64e-6f0c-4a3d-b594-faa6b44e48ab',
"type": 'message',
"text": 'this is test',
"user": 'ULYPAKE5S',
Expand All @@ -32,7 +54,8 @@ def message_event
"thread_ts": '1588623023.005900',
"channel": 'G01354F6A6Q',
"event_ts": '1588623033.006000',
"channel_type": 'group' }
"channel_type": 'group'
}
end

def message_blocks
Expand Down

0 comments on commit 2babfd6

Please sign in to comment.