sms_twilio.rb 861 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Validations::TicketArticleValidator
  3. class SmsTwilio < Backend
  4. MATCHING_TYPES = ['sms'].freeze
  5. def validate_body
  6. return if @record.body.present?
  7. # Allow creation of the article for the unsupported message type (#5289):
  8. # - no body
  9. # - media present
  10. return if @record.preferences.dig('sms', 'NumMedia').to_i.positive?
  11. @record.errors.add :base, __('Body text is required')
  12. end
  13. private
  14. def validator_applies?
  15. channel_id = @record.preferences.dig('sms', 'channel_id')
  16. return false if channel_id.blank?
  17. channel = Channel.find(channel_id)
  18. return false if channel.blank?
  19. # Applicable only for SMS achannel of type Twilio.
  20. channel.options['adapter'] == 'sms/twilio'
  21. end
  22. end
  23. end