1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- module Whatsapp::Webhook
- module Concerns::HandlesError
- private
- def error
- raise NotImplementedError
- end
- def handle_error
-
-
-
-
-
- Rails.logger.error "WhatsApp channel (#{@channel.options[:callback_url_uuid]}) - failed message: #{error[:title]} (#{error[:code]})"
- return if recoverable_error?(error[:code])
- return message_sender_error if sender_error?(error[:code])
- @channel.update!(
- status_out: 'error',
- last_log_out: "#{error[:title]} (#{error[:code]})",
- )
- end
- def recoverable_error?(code)
- [
- 130_472,
- 131_021,
- 131_026,
- 131_047,
- 131_052,
- 131_053,
- ].include?(code)
- end
- def sender_error?(code)
- [
- 131_051,
- ].include?(code)
- end
- def message_sender_error
- body = Translation.translate(
- Setting.get('locale_default') || 'en-us',
- __("Apologies, we're unable to process this kind of message due to restrictions within WhatsApp Business.")
- )
- Whatsapp::Outgoing::Message::Text.new(
- access_token: @channel.options[:access_token],
- phone_number_id: @channel.options[:phone_number_id],
- recipient_number: @data[:entry].first[:changes].first[:value][:messages].first[:from]
- ).deliver(body:)
- end
- end
- end
|