Fix: Creating contacts for already outgoing/echo messages (#4668)

Check if the Instagram contact is already present in the system before throwing the exception.

Fixes: #4666
This commit is contained in:
Tejaswini Chile 2022-05-11 14:29:38 +05:30 committed by GitHub
parent 5c161e0fef
commit 329d305e92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,7 +22,7 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
return unsend_message if message_is_deleted?
ensure_contact(contact_id)
ensure_contact(contact_id) if contacts_first_message?(contact_id)
create_message
end
@ -36,7 +36,7 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
rescue Koala::Facebook::AuthenticationError
@inbox.channel.authorization_error!
raise
rescue StandardError => e
rescue StandardError, Koala::Facebook::ClientError => e
result = {}
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
end
@ -52,6 +52,10 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
@messaging[:message][:is_deleted].present?
end
def contacts_first_message?(ig_scope_id)
@inbox.contact_inboxes.where(source_id: ig_scope_id).empty? && @inbox.channel.instagram_id.present?
end
def unsend_message
message_to_delete = @inbox.messages.find_by(
source_id: @messaging[:message][:mid]