2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-10-16 08:45:15 +00:00
|
|
|
class Channel::Driver::Sms::Massenversand
|
|
|
|
NAME = 'sms/massenversand'.freeze
|
|
|
|
|
|
|
|
def send(options, attr, _notification = false)
|
|
|
|
Rails.logger.info "Sending SMS to recipient #{attr[:recipient]}"
|
|
|
|
|
|
|
|
return true if Setting.get('import_mode')
|
|
|
|
|
|
|
|
Rails.logger.info "Backend sending Massenversand SMS to #{attr[:recipient]}"
|
|
|
|
begin
|
2021-08-16 14:52:36 +00:00
|
|
|
send_create(options, attr)
|
2018-10-16 08:45:15 +00:00
|
|
|
|
|
|
|
true
|
|
|
|
rescue => e
|
2020-08-26 11:46:08 +00:00
|
|
|
message = "Error while performing request to gateway URL '#{url}'"
|
|
|
|
Rails.logger.error message
|
|
|
|
Rails.logger.error e
|
|
|
|
raise message
|
2018-10-16 08:45:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-16 14:52:36 +00:00
|
|
|
def send_create(options, attr)
|
|
|
|
url = build_url(options, attr)
|
|
|
|
|
|
|
|
return if Setting.get('developer_mode')
|
|
|
|
|
|
|
|
response = Faraday.get(url).body
|
|
|
|
return if response.match?('OK')
|
|
|
|
|
|
|
|
message = "Received non-OK response from gateway URL '#{url}'"
|
|
|
|
Rails.logger.error "#{message}: #{response.inspect}"
|
|
|
|
raise message
|
|
|
|
end
|
|
|
|
|
2018-10-16 08:45:15 +00:00
|
|
|
def self.definition
|
|
|
|
{
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Massenversand',
|
|
|
|
adapter: 'sms/massenversand',
|
2018-10-16 08:45:15 +00:00
|
|
|
notification: [
|
2021-11-15 15:58:19 +00:00
|
|
|
{ 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' },
|
|
|
|
{ name: 'options::token', display: __('Token'), tag: 'input', type: 'text', limit: 200, null: false, placeholder: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' },
|
|
|
|
{ name: 'options::sender', display: __('Sender'), tag: 'input', type: 'text', limit: 200, null: false, placeholder: '00491710000000' },
|
2018-10-16 08:45:15 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def build_url(options, attr)
|
|
|
|
params = {
|
|
|
|
authToken: options[:token],
|
2018-12-19 17:31:51 +00:00
|
|
|
getID: 1,
|
|
|
|
msg: attr[:message],
|
|
|
|
msgtype: 'c',
|
|
|
|
receiver: attr[:recipient],
|
|
|
|
sender: options[:sender]
|
2018-10-16 08:45:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-30 09:07:01 +00:00
|
|
|
"#{options[:gateway]}?#{URI.encode_www_form(params)}"
|
2018-10-16 08:45:15 +00:00
|
|
|
end
|
|
|
|
end
|