fix: mentions are not rendered properly in slack (#6762)
This commit is contained in:
@@ -132,5 +132,46 @@ describe Integrations::Slack::SendOnSlackService do
|
||||
expect(hook).to have_received(:authorization_error!)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when message contains mentions' do
|
||||
it 'sends formatted message to slack along with inbox name when identifier not present' do
|
||||
inbox = conversation.inbox
|
||||
message.update!(content: "Hi [@#{contact.name}](mention://user/#{contact.id}/#{contact.name}), welcome to Chatwoot!")
|
||||
formatted_message_text = message.content.gsub(RegexHelper::MENTION_REGEX, '\1')
|
||||
|
||||
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}",
|
||||
username: "#{message.sender.name} (Contact)",
|
||||
thread_ts: nil,
|
||||
icon_url: anything
|
||||
).and_return(slack_message)
|
||||
|
||||
builder.perform
|
||||
end
|
||||
|
||||
it 'sends formatted message to slack when identifier is present' do
|
||||
conversation.update!(identifier: 'random_slack_thread_ts')
|
||||
message.update!(content: "Hi [@#{contact.name}](mention://user/#{contact.id}/#{contact.name}), welcome to Chatwoot!")
|
||||
formatted_message_text = message.content.gsub(RegexHelper::MENTION_REGEX, '\1')
|
||||
|
||||
expect(slack_client).to receive(:chat_postMessage).with(
|
||||
channel: hook.reference_id,
|
||||
text: formatted_message_text,
|
||||
username: "#{message.sender.name} (Contact)",
|
||||
thread_ts: 'random_slack_thread_ts',
|
||||
icon_url: anything
|
||||
).and_return(slack_message)
|
||||
|
||||
builder.perform
|
||||
end
|
||||
|
||||
it 'will not throw error if message content is nil' do
|
||||
message.update!(content: nil)
|
||||
conversation.update!(identifier: 'random_slack_thread_ts')
|
||||
|
||||
expect { builder.perform }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user