feat: handle Channel errors (#11015)
This PR adds missing error handlers for the following channels and cases 1. WhatsApp - Generic Handlers for both Cloud and 360Dialog (Deprecated) 2. Instagram - Handler for a case where there is an HTTP error instead of an `:error` in the 200 response 3. Facebook - Errors from the two sentry issues ([Net::OpenTimeout](https://chatwoot-p3.sentry.io/issues/6164805227) & [JSON::ParserError](https://chatwoot-p3.sentry.io/issues/5903200786)) 4. SMS: Generic handlers for Bandwidth SMS #### Checklist - [x] Bandwidth SMS - [x] Whatsapp Cloud + 360 Dialog - [x] Twilio SMS - [x] Line - [x] Telegram - [x] Instagram - [x] Facebook - [x] GMail - [x] 365 Mail - [x] SMTP Mail --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -37,7 +37,7 @@ class Channel::Sms < ApplicationRecord
|
||||
body = message_body(contact_number, message.content)
|
||||
body['media'] = message.attachments.map(&:download_url) if message.attachments.present?
|
||||
|
||||
send_to_bandwidth(body)
|
||||
send_to_bandwidth(body, message)
|
||||
end
|
||||
|
||||
def send_text_message(contact_number, message_content)
|
||||
@@ -56,7 +56,7 @@ class Channel::Sms < ApplicationRecord
|
||||
}
|
||||
end
|
||||
|
||||
def send_to_bandwidth(body)
|
||||
def send_to_bandwidth(body, message = nil)
|
||||
response = HTTParty.post(
|
||||
"#{api_base_path}/users/#{provider_config['account_id']}/messages",
|
||||
basic_auth: bandwidth_auth,
|
||||
@@ -64,7 +64,22 @@ class Channel::Sms < ApplicationRecord
|
||||
body: body.to_json
|
||||
)
|
||||
|
||||
response.success? ? response.parsed_response['id'] : nil
|
||||
if response.success?
|
||||
response.parsed_response['id']
|
||||
else
|
||||
handle_error(response, message)
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def handle_error(response, message)
|
||||
Rails.logger.error("[#{account_id}] Error sending SMS: #{response.parsed_response['description']}")
|
||||
return if message.blank?
|
||||
|
||||
# https://dev.bandwidth.com/apis/messaging-apis/messaging/#tag/Messages/operation/createMessage
|
||||
message.external_error = response.parsed_response['description']
|
||||
message.status = :failed
|
||||
message.save!
|
||||
end
|
||||
|
||||
def bandwidth_auth
|
||||
|
||||
Reference in New Issue
Block a user