failed.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Whatsapp::Webhook::Message::Status::Failed < Whatsapp::Webhook::Message::Status
  3. include Whatsapp::Webhook::Concerns::HandlesError
  4. private
  5. def create_article?
  6. true
  7. end
  8. def update_related_article?
  9. true
  10. end
  11. def update_related_article_attributes
  12. status_message = "#{error[:title]} (#{error[:code]})"
  13. if error.dig(:error_data, :details).present?
  14. status_message = error.dig(:error_data, :details)
  15. end
  16. preferences = @related_article.preferences
  17. preferences[:whatsapp][:delivery_status] = 'fail'
  18. preferences[:whatsapp][:delivery_status_date] = Time.zone.now
  19. preferences[:whatsapp][:delivery_status_message] = status_message
  20. { preferences: }
  21. end
  22. def body
  23. body = "#{error[:title]} (#{error[:code]})"
  24. if error.dig(:error_data, :details).present?
  25. body = "#{body}\n\n#{error.dig(:error_data, :details)}"
  26. end
  27. if error[:href].present?
  28. body = "#{body}\n\n#{error[:href]}"
  29. end
  30. handle_error
  31. body
  32. end
  33. def error
  34. status[:errors].first
  35. end
  36. end