@@ -12,14 +12,12 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
|
|||||||
|
|
||||||
def perform
|
def perform
|
||||||
create_test_text
|
create_test_text
|
||||||
instagram_id, contact_id = if agent_message_via_echo?
|
instagram_id, contact_id = instagram_and_contact_ids
|
||||||
[@messaging[:sender][:id], @messaging[:recipient][:id]]
|
|
||||||
else
|
|
||||||
[@messaging[:recipient][:id], @messaging[:sender][:id]]
|
|
||||||
end
|
|
||||||
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
|
||||||
|
return if @inbox.channel.reauthorization_required?
|
||||||
|
|
||||||
return unsend_message if message_is_deleted?
|
return unsend_message if message_is_deleted?
|
||||||
|
|
||||||
@@ -30,19 +28,26 @@ class Instagram::MessageText < Instagram::WebhooksBaseService
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def instagram_and_contact_ids
|
||||||
|
if agent_message_via_echo?
|
||||||
|
[@messaging[:sender][:id], @messaging[:recipient][:id]]
|
||||||
|
else
|
||||||
|
[@messaging[:recipient][:id], @messaging[:sender][:id]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
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
|
rescue Koala::Facebook::AuthenticationError => e
|
||||||
@inbox.channel.authorization_error!
|
@inbox.channel.authorization_error!
|
||||||
raise
|
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
||||||
rescue StandardError, Koala::Facebook::ClientError => e
|
rescue StandardError, Koala::Facebook::ClientError => e
|
||||||
result = {}
|
|
||||||
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
ChatwootExceptionTracker.new(e, account: @inbox.account).capture_exception
|
||||||
end
|
end
|
||||||
|
|
||||||
find_or_create_contact(result) if result.present?
|
find_or_create_contact(result) if defined?(result) && result.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def agent_message_via_echo?
|
def agent_message_via_echo?
|
||||||
|
|||||||
Reference in New Issue
Block a user