feat: Handle Instagram send message/attachments errors (#8174)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -66,12 +66,26 @@ class Instagram::SendOnInstagramService < Base::SendOnChannelService
|
||||
query: query
|
||||
)
|
||||
|
||||
Rails.logger.error("Instagram response: #{response['error']} : #{message_content}") if response['error']
|
||||
message.update!(source_id: response['message_id']) if response['message_id'].present?
|
||||
if response[:error].present?
|
||||
Rails.logger.error("Instagram response: #{response['error']} : #{message_content}")
|
||||
message.status = :failed
|
||||
message.external_error = external_error(response)
|
||||
end
|
||||
|
||||
message.source_id = response['message_id'] if response['message_id'].present?
|
||||
message.save!
|
||||
|
||||
response
|
||||
end
|
||||
|
||||
def external_error(response)
|
||||
# https://developers.facebook.com/docs/instagram-api/reference/error-codes/
|
||||
error_message = response[:error][:message]
|
||||
error_code = response[:error][:code]
|
||||
|
||||
"#{error_code} - #{error_message}"
|
||||
end
|
||||
|
||||
def calculate_app_secret_proof(app_secret, access_token)
|
||||
Facebook::Messenger::Configuration::AppSecretProofCalculator.call(
|
||||
app_secret, access_token
|
||||
|
||||
Reference in New Issue
Block a user