mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 02:57:57 +00:00 
			
		
		
		
	chore: Add subject to the slack message (#6404)
This commit is contained in:
		| @@ -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" | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Pranav Raj S
					Pranav Raj S