refactor: add better logs to Instagram::MessageText (#8538)
This commit is contained in:
@@ -16,8 +16,12 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
|
|||||||
inbox_channel(instagram_id)
|
inbox_channel(instagram_id)
|
||||||
# person can connect the channel and then delete the inbox
|
# person can connect the channel and then delete the inbox
|
||||||
return if @inbox.blank?
|
return if @inbox.blank?
|
||||||
|
|
||||||
# This channel might require reauthorization, may be owner might have changed the fb password
|
# This channel might require reauthorization, may be owner might have changed the fb password
|
||||||
return if @inbox.channel.reauthorization_required?
|
if @inbox.channel.reauthorization_required?
|
||||||
|
Rails.logger.info("Skipping message processing as reauthorization is required for inbox #{inbox.id}")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
return unsend_message if message_is_deleted?
|
return unsend_message if message_is_deleted?
|
||||||
|
|
||||||
@@ -36,20 +40,24 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/AbcSize
|
||||||
def ensure_contact(ig_scope_id)
|
def ensure_contact(ig_scope_id)
|
||||||
begin
|
begin
|
||||||
k = Koala::Facebook::API.new(@inbox.channel.page_access_token) if @inbox.facebook?
|
k = Koala::Facebook::API.new(@inbox.channel.page_access_token) if @inbox.facebook?
|
||||||
result = k.get_object(ig_scope_id) || {}
|
result = k.get_object(ig_scope_id) || {}
|
||||||
rescue Koala::Facebook::AuthenticationError => e
|
rescue Koala::Facebook::AuthenticationError => e
|
||||||
@inbox.channel.authorization_error!
|
@inbox.channel.authorization_error!
|
||||||
|
Rails.logger.warn("Authorization error for account #{@inbox.account_id} for #{inbox @inbox.id}")
|
||||||
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
||||||
rescue StandardError, Koala::Facebook::ClientError => e
|
rescue StandardError, Koala::Facebook::ClientError => e
|
||||||
|
Rails.logger.warn("[FacebookUserFetchClientError]: account_id #{@inbox.account_id} inbox_id #{inbox @inbox.id}")
|
||||||
Rails.logger.warn("[FacebookUserFetchClientError]: #{e.message}")
|
Rails.logger.warn("[FacebookUserFetchClientError]: #{e.message}")
|
||||||
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
||||||
end
|
end
|
||||||
|
|
||||||
find_or_create_contact(result) if defined?(result) && result.present?
|
find_or_create_contact(result) if defined?(result) && result.present?
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/AbcSize
|
||||||
|
|
||||||
def agent_message_via_echo?
|
def agent_message_via_echo?
|
||||||
@messaging[:message][:is_echo].present?
|
@messaging[:message][:is_echo].present?
|
||||||
|
|||||||
Reference in New Issue
Block a user