diff --git a/app/services/facebook/send_on_facebook_service.rb b/app/services/facebook/send_on_facebook_service.rb index ed3b7e4ab..baf72ef6e 100644 --- a/app/services/facebook/send_on_facebook_service.rb +++ b/app/services/facebook/send_on_facebook_service.rb @@ -49,7 +49,7 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService recipient: { id: contact.get_source_id(inbox.id) }, message: fb_text_message_payload, messaging_type: 'MESSAGE_TAG', - tag: 'ACCOUNT_UPDATE' + tag: message_tag } end @@ -90,10 +90,14 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService } }, messaging_type: 'MESSAGE_TAG', - tag: 'ACCOUNT_UPDATE' + tag: message_tag } end + def message_tag + @message_tag ||= GlobalConfigService.load('ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT', nil) ? 'HUMAN_AGENT' : 'ACCOUNT_UPDATE' + end + def attachment_type(attachment) return attachment.file_type if %w[image audio video file].include? attachment.file_type diff --git a/spec/services/facebook/send_on_facebook_service_spec.rb b/spec/services/facebook/send_on_facebook_service_spec.rb index 4d5f9babd..f99b1c469 100644 --- a/spec/services/facebook/send_on_facebook_service_spec.rb +++ b/spec/services/facebook/send_on_facebook_service_spec.rb @@ -7,6 +7,7 @@ describe Facebook::SendOnFacebookService do allow(Facebook::Messenger::Subscriptions).to receive(:subscribe).and_return(true) allow(bot).to receive(:deliver).and_return({ recipient_id: '1008372609250235', message_id: 'mid.1456970487936:c34767dfe57ee6e339' }.to_json) create(:message, message_type: :incoming, inbox: facebook_inbox, account: account, conversation: conversation) + GlobalConfig.clear_cache end let!(:account) { create(:account) } @@ -90,6 +91,17 @@ describe Facebook::SendOnFacebookService do }, { page_id: facebook_channel.page_id }) end + it 'sends with HUMAN_AGENT tag when ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT is enabled' do + with_modified_env ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT: 'true' do + message = create(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation) + described_class.new(message: message).perform + expect(bot).to have_received(:deliver).with( + hash_including(tag: 'HUMAN_AGENT'), + { page_id: facebook_channel.page_id } + ) + end + end + it 'if message is sent with multiple attachments' do message = build(:message, content: nil, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation) avatar = message.attachments.new(account_id: message.account_id, file_type: :image)