2018-05-28 23:45:29 +00:00
|
|
|
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class Integration::CtiController < ApplicationController
|
|
|
|
skip_before_action :verify_csrf_token
|
|
|
|
before_action :check_configured, :check_token
|
|
|
|
|
|
|
|
# notify about inbound call / block inbound call
|
|
|
|
def event
|
2019-07-09 22:07:32 +00:00
|
|
|
local_params = ActiveSupport::HashWithIndifferentAccess.new(params.permit!.to_h)
|
|
|
|
|
|
|
|
cti = Cti::Driver::Cti.new(params: local_params, config: config_integration)
|
|
|
|
|
|
|
|
result = cti.process
|
|
|
|
|
|
|
|
# check if inbound call should get rejected
|
|
|
|
if result[:action] == 'reject'
|
|
|
|
response_ok(action: 'reject', reason: 'busy')
|
2018-05-28 23:45:29 +00:00
|
|
|
return true
|
2019-07-09 22:07:32 +00:00
|
|
|
end
|
|
|
|
|
2019-07-31 08:23:48 +00:00
|
|
|
# check if outbound call changes the outbound caller_id
|
2019-07-09 22:07:32 +00:00
|
|
|
if result[:action] == 'set_caller_id'
|
|
|
|
data = {
|
|
|
|
action: 'dial',
|
|
|
|
caller_id: result[:params][:from_caller_id],
|
|
|
|
number: result[:params][:to_caller_id],
|
|
|
|
}
|
|
|
|
response_ok(data)
|
2018-05-28 23:45:29 +00:00
|
|
|
return true
|
|
|
|
end
|
2019-07-09 22:07:32 +00:00
|
|
|
|
|
|
|
if result[:action] == 'invalid_direction'
|
|
|
|
response_error('Invalid direction!')
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
response_ok({})
|
2018-05-28 23:45:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def check_token
|
|
|
|
if Setting.get('cti_token') != params[:token]
|
|
|
|
response_unauthorized('Invalid token, please contact your admin!')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_configured
|
|
|
|
http_log_config facility: 'cti'
|
|
|
|
|
|
|
|
if !Setting.get('cti_integration')
|
|
|
|
response_error('Feature is disable, please contact your admin to enable it!')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if config_integration.blank? || config_integration[:inbound].blank? || config_integration[:outbound].blank?
|
|
|
|
response_error('Feature not configured, please contact your admin!')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def config_integration
|
|
|
|
@config_integration ||= Setting.get('cti_config')
|
|
|
|
end
|
|
|
|
|
|
|
|
def response_error(error)
|
|
|
|
render json: { error: error }, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
|
|
|
|
def response_unauthorized(error)
|
|
|
|
render json: { error: error }, status: :unauthorized
|
|
|
|
end
|
|
|
|
|
2019-07-09 22:07:32 +00:00
|
|
|
def response_ok(data)
|
|
|
|
render json: data, status: :ok
|
|
|
|
end
|
|
|
|
|
2018-05-28 23:45:29 +00:00
|
|
|
end
|