Class: Telephony::AgentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/telephony/agents_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



40
41
42
43
44
# File 'app/controllers/telephony/agents_controller.rb', line 40

def index
  agents = Agent.all_transferable_for_csr_id params[:csr_id]

  render :json => agents
end

#show_by_csr_idObject



5
6
7
8
# File 'app/controllers/telephony/agents_controller.rb', line 5

def show_by_csr_id
  agent = Agent.find_by_csr_id params[:csr_id]
  render json: agent.as_json(only: [:id, :csr_id, :name], methods: :active_conversation_id)
end

#statusObject



31
32
33
34
35
36
37
38
# File 'app/controllers/telephony/agents_controller.rb', line 31

def status
  agent = Agent.find_by_csr_id params[:id]
  agent.with_lock do
    agent.fire_events params[:event]
  end

  render :json => { :csr_id => agent.csr_id, :status => agent.status }
end

#terminate_active_callObject



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/telephony/agents_controller.rb', line 10

def terminate_active_call
  agent = Agent.find_by_csr_id params[:id]

  if agent
    agent.with_lock { agent.terminate_active_call }
    render :json => {}
  else
    render status: :bad_request, json: { errors: 'Csr Id invalid' }
  end
end

#updateObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/telephony/agents_controller.rb', line 21

def update
  agent = Agent.update_or_create_by_widget_data params

  if agent.valid?
    render status: :ok, json: { conversation_id: agent.active_conversation_id }
  else
    render status: :bad_request, json: { errors: agent.errors.full_messages }
  end
end