Compare commits

...
Author SHA1 Message Date
Muhsin Keloth daef6e0d17 fix: slack attachments 2023-08-10 13:57:49 +05:30
Muhsin Keloth 8fe4ebde9b fix: create thread if conversation identifier changes 2023-08-10 13:17:07 +05:30
3 changed files with 40 additions and 2 deletions
@@ -36,7 +36,7 @@ class Integrations::Slack::IncomingMessageBuilder
def should_process_event?
return true if params[:type] != 'event_callback'
params[:event][:user].present? && params[:event][:subtype].blank?
params[:event][:user].present? && (params[:event][:subtype].blank? || params[:event][:subtype] == 'file_share')
end
def supported_event?
@@ -128,7 +128,8 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
end
def update_reference_id
return if conversation.identifier
# If the conversation identifier is present and conversation identifier is not equal to slack message ts, then do nothing
return if conversation.identifier && conversation.identifier == @slack_message['ts']
conversation.update!(identifier: @slack_message['ts'])
end
@@ -97,6 +97,43 @@ describe Integrations::Slack::SendOnSlackService do
expect(message.external_source_id_slack).to eq 'cw-origin-6789.12345'
end
it 'send a message to a previously non-existent slack thread' do
allow(slack_message).to receive(:[]).with('ts').and_return('1245.6789')
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)
builder.perform
expect(conversation.identifier).to eq '1245.6789'
end
it 'send a message to a differnt channel in slack' do
allow(slack_message).to receive(:[]).with('ts').and_return('1691652432.896169')
hook.update!(reference_id: 'C12345')
expect(slack_client).to receive(:chat_postMessage).with(
channel: 'C12345',
text: message.content,
username: "#{message.sender.name} (Contact)",
thread_ts: conversation.identifier,
icon_url: anything,
unfurl_links: true
).and_return(slack_message)
builder.perform
expect(hook.reload.reference_id).to eq 'C12345'
expect(conversation.identifier).to eq '1691652432.896169'
end
it 'sent attachment on slack' do
expect(slack_client).to receive(:chat_postMessage).with(
channel: hook.reference_id,