feat: Handle Facebook send message/attachments errors (#8197)

This commit is contained in:
Muhsin Keloth
2023-10-25 21:29:25 +05:30
committed by GitHub
parent 4fc62ed9ae
commit 58f47eb02c
2 changed files with 20 additions and 1 deletions

View File

@@ -15,7 +15,9 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
def send_message_to_facebook(delivery_params)
result = Facebook::Messenger::Bot.deliver(delivery_params, page_id: channel.page_id)
message.update!(source_id: JSON.parse(result)['message_id'])
parsed_result = JSON.parse(result)
message.update!(status: :failed, external_error: external_error(parsed_result)) if parsed_result['error'].present?
message.update!(source_id: parsed_result['message_id']) if parsed_result['message_id'].present?
end
def fb_text_message_params
@@ -27,6 +29,14 @@ class Facebook::SendOnFacebookService < Base::SendOnChannelService
}
end
def external_error(response)
# https://developers.facebook.com/docs/graph-api/guides/error-handling/
error_message = response['error']['message']
error_code = response['error']['code']
"#{error_code} - #{error_message}"
end
def fb_attachment_message_params
attachment = message.attachments.first
{