Fix: skip invalid access token from sentry (#6639)
This commit is contained in:
@@ -9,9 +9,8 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
|
|||||||
send_message_to_facebook fb_text_message_params if message.content.present?
|
send_message_to_facebook fb_text_message_params if message.content.present?
|
||||||
send_message_to_facebook fb_attachment_message_params if message.attachments.present?
|
send_message_to_facebook fb_attachment_message_params if message.attachments.present?
|
||||||
rescue Facebook::Messenger::FacebookError => e
|
rescue Facebook::Messenger::FacebookError => e
|
||||||
ChatwootExceptionTracker.new(e, account: message.account, user: message.sender).capture_exception
|
|
||||||
# TODO : handle specific errors or else page will get disconnected
|
# TODO : handle specific errors or else page will get disconnected
|
||||||
# channel.authorization_error!
|
handle_facebook_error(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_message_to_facebook(delivery_params)
|
def send_message_to_facebook(delivery_params)
|
||||||
@@ -67,4 +66,13 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
|
|||||||
def last_incoming_message
|
def last_incoming_message
|
||||||
conversation.messages.incoming.last
|
conversation.messages.incoming.last
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_facebook_error(exception)
|
||||||
|
# Refer: https://github.com/jgorset/facebook-messenger/blob/64fe1f5cef4c1e3fca295b205037f64dfebdbcab/lib/facebook/messenger/error.rb
|
||||||
|
if exception.to_s.include?('The session has been invalidated') || exception.to_s.include?('Error validating access token')
|
||||||
|
channel.authorization_error!
|
||||||
|
else
|
||||||
|
ChatwootExceptionTracker.new(exception, account: message.account, user: message.sender).capture_exception
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -52,6 +52,14 @@ describe Facebook::SendOnFacebookService do
|
|||||||
expect(bot).to have_received(:deliver)
|
expect(bot).to have_received(:deliver)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'raise and exception to validate access token' do
|
||||||
|
message = create(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation)
|
||||||
|
allow(bot).to receive(:deliver).and_raise(Facebook::Messenger::FacebookError.new('message' => 'Error validating access token'))
|
||||||
|
::Facebook::SendOnFacebookService.new(message: message).perform
|
||||||
|
|
||||||
|
expect(facebook_channel.authorization_error_count).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
it 'if message with attachment is sent from chatwoot and is outgoing' do
|
it 'if message with attachment is sent from chatwoot and is outgoing' do
|
||||||
message = build(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation)
|
message = build(:message, message_type: 'outgoing', inbox: facebook_inbox, account: account, conversation: conversation)
|
||||||
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
|
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
|
||||||
|
|||||||
Reference in New Issue
Block a user