feat(facebook): Mark Messenger native-app echoes as external echo message (#13665)

When agents send replies from the native Facebook Messenger app (not
Chatwoot), echo events were created without external_echo metadata and
could be misrepresented in the UI. This change updates Messenger echo
message creation to:

- set content_attributes.external_echo = true for outgoing_echo messages
- set echo message status to delivered
- keep sender as nil for echo messages (existing behavior)

<img width="2614" height="1264" alt="CleanShot 2026-02-26 at 16 32
04@2x"
src="https://github.com/user-attachments/assets/ba61c941-465d-4893-814e-855e6b6c79e8"
/>
This commit is contained in:
Muhsin Keloth
2026-02-26 19:05:15 +04:00
committed by GitHub
parent 7acd239c70
commit bdcc62f1b0
2 changed files with 37 additions and 3 deletions

View File

@@ -105,15 +105,19 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
end
def message_params
content_attributes = {
in_reply_to_external_id: response.in_reply_to_external_id
}
content_attributes[:external_echo] = true if @outgoing_echo
{
account_id: conversation.account_id,
inbox_id: conversation.inbox_id,
message_type: @message_type,
status: @outgoing_echo ? :delivered : :sent,
content: response.content,
source_id: response.identifier,
content_attributes: {
in_reply_to_external_id: response.in_reply_to_external_id
},
content_attributes: content_attributes,
sender: @outgoing_echo ? nil : @contact_inbox.contact
}
end

View File

@@ -59,6 +59,36 @@ describe Messages::Facebook::MessageBuilder do
expect(contact.name).to eq(default_name)
end
it 'marks echo messages as external echo messages' do
allow(Koala::Facebook::API).to receive(:new).and_return(fb_object)
allow(fb_object).to receive(:get_object).and_return(
{
first_name: 'Jane',
last_name: 'Dae',
account_id: facebook_channel.inbox.account_id,
profile_pic: 'https://chatwoot-assets.local/sample.png'
}.with_indifferent_access
)
echo_message_object = {
messaging: {
sender: { id: facebook_channel.page_id },
recipient: { id: '3383290475046708' },
message: { mid: 'm_echo_1', text: 'Echo testing', is_echo: true, app_id: '263902037430900' }
}
}.to_json
echo_message = Integrations::Facebook::MessageParser.new(echo_message_object)
described_class.new(echo_message, facebook_channel.inbox, outgoing_echo: true).perform
message = facebook_channel.inbox.messages.find_by(source_id: 'm_echo_1')
expect(message).to be_present
expect(message.message_type).to eq('outgoing')
expect(message.sender).to be_nil
expect(message.status).to eq('delivered')
expect(message.content_attributes['external_echo']).to be true
end
context 'when lock to single conversation' do
subject(:mocked_message_builder) do
described_class.new(mocked_incoming_fb_text_message, facebook_channel.inbox).perform