chore: Update conversation thread rendering in Slack (#6812)
This commit is contained in:
@@ -38,10 +38,12 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
|
|||||||
|
|
||||||
def message_content
|
def message_content
|
||||||
private_indicator = message.private? ? 'private: ' : ''
|
private_indicator = message.private? ? 'private: ' : ''
|
||||||
|
sanitized_content = ActionView::Base.full_sanitizer.sanitize(message_text)
|
||||||
|
|
||||||
if conversation.identifier.present?
|
if conversation.identifier.present?
|
||||||
"#{private_indicator}#{message_text}"
|
"#{private_indicator}#{sanitized_content}"
|
||||||
else
|
else
|
||||||
"#{formatted_inbox_name}#{formatted_conversation_link}#{email_subject_line}\n#{message_text}"
|
"#{formatted_inbox_name}#{formatted_conversation_link}#{email_subject_line}\n#{sanitized_content}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -58,7 +60,7 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def formatted_conversation_link
|
def formatted_conversation_link
|
||||||
"*Conversation:* #{link_to_conversation}\n"
|
"#{link_to_conversation} to view the conversation.\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_subject_line
|
def email_subject_line
|
||||||
@@ -87,10 +89,11 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
|
|||||||
def post_message
|
def post_message
|
||||||
@slack_message = slack_client.chat_postMessage(
|
@slack_message = slack_client.chat_postMessage(
|
||||||
channel: hook.reference_id,
|
channel: hook.reference_id,
|
||||||
text: ActionView::Base.full_sanitizer.sanitize(message_content),
|
text: message_content,
|
||||||
username: sender_name(message.sender),
|
username: sender_name(message.sender),
|
||||||
thread_ts: conversation.identifier,
|
thread_ts: conversation.identifier,
|
||||||
icon_url: avatar_url(message.sender)
|
icon_url: avatar_url(message.sender),
|
||||||
|
unfurl_links: conversation.identifier.present?
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -141,6 +144,6 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def link_to_conversation
|
def link_to_conversation
|
||||||
"#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{conversation.account_id}/conversations/#{conversation.display_id}"
|
"<#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{conversation.account_id}/conversations/#{conversation.display_id}|Click here>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
let(:slack_message_content) { double }
|
let(:slack_message_content) { double }
|
||||||
let(:slack_client) { double }
|
let(:slack_client) { double }
|
||||||
let(:builder) { described_class.new(message: message, hook: hook) }
|
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}" }
|
let(:conversation_link) do
|
||||||
|
"<#{ENV.fetch('FRONTEND_URL', nil)}/app/accounts/#{account.id}/conversations/#{conversation.display_id}|Click here> to view the conversation."
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(builder).to receive(:slack_client).and_return(slack_client)
|
allow(builder).to receive(:slack_client).and_return(slack_client)
|
||||||
@@ -34,10 +36,11 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
|
|
||||||
expect(slack_client).to receive(:chat_postMessage).with(
|
expect(slack_client).to receive(:chat_postMessage).with(
|
||||||
channel: hook.reference_id,
|
channel: hook.reference_id,
|
||||||
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n*Conversation:* #{conversation_link}\n\n#{message.content}",
|
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n#{conversation_link}\n\n#{message.content}",
|
||||||
username: "#{message.sender.name} (Contact)",
|
username: "#{message.sender.name} (Contact)",
|
||||||
thread_ts: nil,
|
thread_ts: nil,
|
||||||
icon_url: anything
|
icon_url: anything,
|
||||||
|
unfurl_links: false
|
||||||
).and_return(slack_message)
|
).and_return(slack_message)
|
||||||
|
|
||||||
builder.perform
|
builder.perform
|
||||||
@@ -59,11 +62,12 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
|
|
||||||
expect(slack_client).to receive(:chat_postMessage).with(
|
expect(slack_client).to receive(:chat_postMessage).with(
|
||||||
channel: hook.reference_id,
|
channel: hook.reference_id,
|
||||||
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n*Conversation:* #{conversation_link}\n" \
|
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n#{conversation_link}\n" \
|
||||||
"*Subject:* Sample subject line\n\n\n#{message.content}",
|
"*Subject:* Sample subject line\n\n\n#{message.content}",
|
||||||
username: "#{message.sender.name} (Contact)",
|
username: "#{message.sender.name} (Contact)",
|
||||||
thread_ts: nil,
|
thread_ts: nil,
|
||||||
icon_url: anything
|
icon_url: anything,
|
||||||
|
unfurl_links: false
|
||||||
).and_return(slack_message)
|
).and_return(slack_message)
|
||||||
|
|
||||||
builder.perform
|
builder.perform
|
||||||
@@ -84,7 +88,8 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
text: message.content,
|
text: message.content,
|
||||||
username: "#{message.sender.name} (Contact)",
|
username: "#{message.sender.name} (Contact)",
|
||||||
thread_ts: conversation.identifier,
|
thread_ts: conversation.identifier,
|
||||||
icon_url: anything
|
icon_url: anything,
|
||||||
|
unfurl_links: true
|
||||||
).and_return(slack_message)
|
).and_return(slack_message)
|
||||||
|
|
||||||
builder.perform
|
builder.perform
|
||||||
@@ -98,7 +103,8 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
text: message.content,
|
text: message.content,
|
||||||
username: "#{message.sender.name} (Contact)",
|
username: "#{message.sender.name} (Contact)",
|
||||||
thread_ts: conversation.identifier,
|
thread_ts: conversation.identifier,
|
||||||
icon_url: anything
|
icon_url: anything,
|
||||||
|
unfurl_links: true
|
||||||
).and_return(slack_message)
|
).and_return(slack_message)
|
||||||
|
|
||||||
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
|
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
|
||||||
@@ -131,7 +137,8 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
text: template_message.content,
|
text: template_message.content,
|
||||||
username: "#{template_message.sender.name} (Contact)",
|
username: "#{template_message.sender.name} (Contact)",
|
||||||
thread_ts: conversation.identifier,
|
thread_ts: conversation.identifier,
|
||||||
icon_url: anything
|
icon_url: anything,
|
||||||
|
unfurl_links: true
|
||||||
).and_return(slack_message)
|
).and_return(slack_message)
|
||||||
|
|
||||||
builder.perform
|
builder.perform
|
||||||
@@ -145,7 +152,8 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
text: message.content,
|
text: message.content,
|
||||||
username: "#{message.sender.name} (Contact)",
|
username: "#{message.sender.name} (Contact)",
|
||||||
thread_ts: conversation.identifier,
|
thread_ts: conversation.identifier,
|
||||||
icon_url: anything
|
icon_url: anything,
|
||||||
|
unfurl_links: true
|
||||||
).and_raise(Slack::Web::Api::Errors::AccountInactive.new('Account disconnected'))
|
).and_raise(Slack::Web::Api::Errors::AccountInactive.new('Account disconnected'))
|
||||||
|
|
||||||
allow(hook).to receive(:authorization_error!)
|
allow(hook).to receive(:authorization_error!)
|
||||||
@@ -164,10 +172,11 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
|
|
||||||
expect(slack_client).to receive(:chat_postMessage).with(
|
expect(slack_client).to receive(:chat_postMessage).with(
|
||||||
channel: hook.reference_id,
|
channel: hook.reference_id,
|
||||||
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n*Conversation:* #{conversation_link}\n\n#{formatted_message_text}",
|
text: "\n*Inbox:* #{inbox.name} (#{inbox.inbox_type})\n#{conversation_link}\n\n#{formatted_message_text}",
|
||||||
username: "#{message.sender.name} (Contact)",
|
username: "#{message.sender.name} (Contact)",
|
||||||
thread_ts: nil,
|
thread_ts: nil,
|
||||||
icon_url: anything
|
icon_url: anything,
|
||||||
|
unfurl_links: false
|
||||||
).and_return(slack_message)
|
).and_return(slack_message)
|
||||||
|
|
||||||
builder.perform
|
builder.perform
|
||||||
@@ -183,7 +192,8 @@ describe Integrations::Slack::SendOnSlackService do
|
|||||||
text: formatted_message_text,
|
text: formatted_message_text,
|
||||||
username: "#{message.sender.name} (Contact)",
|
username: "#{message.sender.name} (Contact)",
|
||||||
thread_ts: 'random_slack_thread_ts',
|
thread_ts: 'random_slack_thread_ts',
|
||||||
icon_url: anything
|
icon_url: anything,
|
||||||
|
unfurl_links: true
|
||||||
).and_return(slack_message)
|
).and_return(slack_message)
|
||||||
|
|
||||||
builder.perform
|
builder.perform
|
||||||
|
|||||||
Reference in New Issue
Block a user