fix: Add link to conversation in slack message (#6768)

This commit is contained in:
Tejaswini Chile
2023-03-30 13:03:19 +05:30
committed by GitHub
parent cef44bc557
commit d8604107aa
2 changed files with 20 additions and 5 deletions

View File

@@ -37,18 +37,26 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
if conversation.identifier.present?
"#{private_indicator}#{message_text}"
else
"#{formatted_inbox_name}#{email_subject_line}\n#{message_text}"
"#{formatted_inbox_name}#{formatted_conversation_link}#{email_subject_line}\n#{message_text}"
end
end
def message_text
message.content.present? ? message.content.gsub(MENTION_REGEX, '\1') : message.content
if message.content.present?
message.content.gsub(MENTION_REGEX, '\1')
else
message.content
end
end
def formatted_inbox_name
"\n*Inbox:* #{message.inbox.name} (#{message.inbox.inbox_type})\n"
end
def formatted_conversation_link
"*Conversation:* #{link_to_conversation}\n"
end
def email_subject_line
return '' unless message.inbox.email?
@@ -127,4 +135,8 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
def slack_client
@slack_client ||= Slack::Web::Client.new(token: hook.access_token)
end
def link_to_conversation
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{conversation.account_id}/conversations/#{conversation.display_id}"
end
end

View File

@@ -9,11 +9,13 @@ describe Integrations::Slack::SendOnSlackService do
let!(:message) do
create(:message, account: conversation.account, inbox: conversation.inbox, conversation: conversation)
end
let(:slack_message) { double }
let(:file_attachment) { double }
let(:slack_message_content) { double }
let(:slack_client) { double }
let(:builder) { described_class.new(message: message, hook: hook) }
let(:conversation_link) { "#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{account.id}/conversations/#{conversation.display_id}" }
before do
allow(builder).to receive(:slack_client).and_return(slack_client)
@@ -29,7 +31,7 @@ describe Integrations::Slack::SendOnSlackService do
expect(slack_client).to receive(:chat_postMessage).with(
channel: hook.reference_id,
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n\n#{message.content}",
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n*Conversation:* #{conversation_link}\n\n#{message.content}",
username: "#{message.sender.name} (Contact)",
thread_ts: nil,
icon_url: anything
@@ -54,7 +56,8 @@ describe Integrations::Slack::SendOnSlackService do
expect(slack_client).to receive(:chat_postMessage).with(
channel: hook.reference_id,
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n*Subject:* Sample subject line\n\n\n#{message.content}",
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n*Conversation:* #{conversation_link}\n" \
"*Subject:* Sample subject line\n\n\n#{message.content}",
username: "#{message.sender.name} (Contact)",
thread_ts: nil,
icon_url: anything
@@ -141,7 +144,7 @@ describe Integrations::Slack::SendOnSlackService do
expect(slack_client).to receive(:chat_postMessage).with(
channel: hook.reference_id,
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n\n#{formatted_message_text}",
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n*Conversation:* #{conversation_link}\n\n#{formatted_message_text}",
username: "#{message.sender.name} (Contact)",
thread_ts: nil,
icon_url: anything