fix: Prevent creating duplicate messages via Instagram echo events (#11535)
Fixes https://linear.app/chatwoot/issue/CW-4383/copilot-resolution-message-creating-duplicate-conversations-due-to and https://linear.app/chatwoot/issue/CW-4287/instagram-channel-missing-existing-source-id-check When the copilot/system resolves a conversation with a system resolve message (with `lock_to_single_conversation` disabled), echo events were creating new conversations instead of using existing ones. This occurred because we were checking the echo_id in the new conversation rather than in the resolved conversation. This PR fixes the issue by checking if the message exists anywhere in the system instead of checking within a particular conversation.
This commit is contained in:
@@ -152,11 +152,13 @@ class Messages::Instagram::BaseMessageBuilder < Messages::Messenger::MessageBuil
|
||||
end
|
||||
|
||||
def message_already_exists?
|
||||
cw_message = conversation.messages.where(
|
||||
source_id: @messaging[:message][:mid]
|
||||
).first
|
||||
find_message_by_source_id(@messaging[:message][:mid]).present?
|
||||
end
|
||||
|
||||
cw_message.present?
|
||||
def find_message_by_source_id(source_id)
|
||||
return unless source_id
|
||||
|
||||
@message = Message.find_by(source_id: source_id)
|
||||
end
|
||||
|
||||
def all_unsupported_files?
|
||||
|
||||
Reference in New Issue
Block a user