chore: Add subject to the slack message (#6404)

This commit is contained in:
Pranav Raj S
2023-02-06 12:42:06 -08:00
committed by GitHub
parent 527bf593b1
commit d672aa357b
2 changed files with 42 additions and 2 deletions

View File

@@ -36,10 +36,23 @@ class Integrations::Slack::SendOnSlackService < Base::SendOnChannelService
if conversation.identifier.present?
"#{private_indicator}#{message.content}"
else
"\n*Inbox:* #{message.inbox.name} (#{message.inbox.inbox_type})\n\n#{message.content}"
"#{formatted_inbox_name}#{email_subject_line}\n#{message.content}"
end
end
def formatted_inbox_name
"\n*Inbox:* #{message.inbox.name} (#{message.inbox.inbox_type})\n"
end
def email_subject_line
return '' unless message.inbox.email?
email_payload = message.content_attributes['email']
return "*Subject:* #{email_payload['subject']}\n\n" if email_payload.present? && email_payload['subject'].present?
''
end
def avatar_url(sender)
sender_type = sender.instance_of?(Contact) ? 'contact' : 'user'
"#{ENV.fetch('FRONTEND_URL', nil)}/integrations/slack/#{sender_type}.png"

View File

@@ -2,7 +2,8 @@ require 'rails_helper'
describe Integrations::Slack::SendOnSlackService do
let!(:contact) { create(:contact) }
let!(:conversation) { create(:conversation, contact: contact, identifier: nil) }
let(:channel_email) { create(:channel_email) }
let!(:conversation) { create(:conversation, inbox: channel_email.inbox, contact: contact, identifier: nil) }
let(:account) { conversation.account }
let!(:hook) { create(:integrations_hook, account: account) }
let!(:message) do
@@ -38,6 +39,32 @@ describe Integrations::Slack::SendOnSlackService do
expect(conversation.reload.identifier).to eq '12345.6789'
end
context 'with subject line in email' do
let(:message) do
create(:message,
content_attributes: { 'email': { 'subject': 'Sample subject line' } },
content: 'Sample Body',
account: conversation.account,
inbox: conversation.inbox, conversation: conversation)
end
it 'creates slack message with subject line' do
inbox = conversation.inbox
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}",
username: "#{message.sender.name} (Contact)",
thread_ts: nil,
icon_url: anything
).and_return(slack_message)
builder.perform
expect(conversation.reload.identifier).to eq '12345.6789'
end
end
end
context 'with identifier' do