massenversand.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Channel::Driver::Sms::Massenversand
  3. NAME = 'sms/massenversand'.freeze
  4. def deliver(options, attr, _notification = false)
  5. Rails.logger.info "Sending SMS to recipient #{attr[:recipient]}"
  6. return true if Setting.get('import_mode')
  7. Rails.logger.info "Backend sending Massenversand SMS to #{attr[:recipient]}"
  8. begin
  9. send_create(options, attr)
  10. true
  11. rescue => e
  12. url = build_url(options, attr)
  13. message = "Error while performing request to gateway URL '#{url}'"
  14. Rails.logger.error message
  15. Rails.logger.error e
  16. raise message
  17. end
  18. end
  19. def send_create(options, attr)
  20. url = build_url(options, attr)
  21. return if Setting.get('developer_mode')
  22. response = Faraday.get(url).body
  23. return if response.match?('OK')
  24. message = "Received non-OK response from gateway URL '#{url}'"
  25. Rails.logger.error "#{message}: #{response.inspect}"
  26. raise message
  27. end
  28. def self.definition
  29. {
  30. name: 'Massenversand',
  31. adapter: 'sms/massenversand',
  32. notification: [
  33. { name: 'options::gateway', display: __('Gateway'), tag: 'input', type: 'text', limit: 200, null: false, placeholder: 'https://gate1.goyyamobile.com/sms/sendsms.asp', default: 'https://gate1.goyyamobile.com/sms/sendsms.asp' },
  34. { name: 'options::token', display: __('Token'), tag: 'input', type: 'text', limit: 200, null: false, placeholder: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' },
  35. { name: 'options::sender', display: __('Sender'), tag: 'input', type: 'text', limit: 200, null: false, placeholder: '00491710000000' },
  36. ]
  37. }
  38. end
  39. private
  40. def build_url(options, attr)
  41. params = {
  42. authToken: options[:token],
  43. getID: 1,
  44. msg: attr[:message],
  45. msgtype: 'c',
  46. receiver: attr[:recipient],
  47. sender: options[:sender]
  48. }
  49. "#{options[:gateway]}?#{URI.encode_www_form(params)}"
  50. end
  51. end