feat(facebook): use HUMAN_AGENT tag for Messenger replies when human-agent config is enabled (#13690)
This PR updates Facebook Messenger outbound tagging in Chatwoot to support Human Agent messaging when enabled. Previously, Facebook outbound text and attachment messages were always sent with: ``` messaging_type: MESSAGE_TAG tag: ACCOUNT_UPDATE ``` With this change, the tag is selected dynamically: ``` HUMAN_AGENT when ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT is enabled ACCOUNT_UPDATE as fallback when the flag is disabled ```
This commit is contained in:
parent
ab93821d2b
commit
9aacc0335b
@ -49,7 +49,7 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
|
|||||||
recipient: { id: contact.get_source_id(inbox.id) },
|
recipient: { id: contact.get_source_id(inbox.id) },
|
||||||
message: fb_text_message_payload,
|
message: fb_text_message_payload,
|
||||||
messaging_type: 'MESSAGE_TAG',
|
messaging_type: 'MESSAGE_TAG',
|
||||||
tag: 'ACCOUNT_UPDATE'
|
tag: message_tag
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -90,10 +90,14 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
messaging_type: 'MESSAGE_TAG',
|
messaging_type: 'MESSAGE_TAG',
|
||||||
tag: 'ACCOUNT_UPDATE'
|
tag: message_tag
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def message_tag
|
||||||
|
@message_tag ||= GlobalConfigService.load('ENABLE_MESSENGER_CHANNEL_HUMAN_AGENT', nil) ? 'HUMAN_AGENT' : 'ACCOUNT_UPDATE'
|
||||||
|
end
|
||||||
|
|
||||||
def attachment_type(attachment)
|
def attachment_type(attachment)
|
||||||
return attachment.file_type if %w[image audio video file].include? attachment.file_type
|
return attachment.file_type if %w[image audio video file].include? attachment.file_type
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ describe Facebook::SendOnFacebookService do
|
|||||||
allow(Facebook::Messenger::Subscriptions).to receive(:subscribe).and_return(true)
|
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)
|
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)
|
create(:message, message_type: :incoming, inbox: facebook_inbox, account: account, conversation: conversation)
|
||||||
|
GlobalConfig.clear_cache
|
||||||
end
|
end
|
||||||
|
|
||||||
let!(:account) { create(:account) }
|
let!(:account) { create(:account) }
|
||||||
@ -90,6 +91,17 @@ describe Facebook::SendOnFacebookService do
|
|||||||
}, { page_id: facebook_channel.page_id })
|
}, { page_id: facebook_channel.page_id })
|
||||||
end
|
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
|
it 'if message is sent with multiple attachments' do
|
||||||
message = build(:message, content: nil, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation)
|
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)
|
avatar = message.attachments.new(account_id: message.account_id, file_type: :image)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user