Class: Telephony::ConversationsController

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

Instance Method Summary collapse

Instance Method Details

#countsObject



11
12
13
14
# File 'app/controllers/telephony/conversations_controller.rb', line 11

def counts
  counts = ConversationData.counts params
  render json: counts
end

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/telephony/conversations_controller.rb', line 25

def create
  conversation = Conversation.begin! params

  render json: {
    id:     conversation.id,
    number: conversation.customer.number
  }
rescue Telephony::Error::Connection => e
  msg = 'Call failed. Please try again in a few seconds.'
  Rails.logger.error "#{msg} - #{e.message} - #{params}"
  errors = [msg, e.message]

  render json: { errors: errors }, status: :server_error
end

#holdObject



47
48
49
50
51
52
# File 'app/controllers/telephony/conversations_controller.rb', line 47

def hold
  lock_conversation(params['id'], 'Hold failed. Please try again in a few seconds.') do |conversation|
    conversation.hold!
    render json: {}
  end
end

#indexObject



6
7
8
9
# File 'app/controllers/telephony/conversations_controller.rb', line 6

def index
  conversations = ConversationData.filter params
  render json: conversations
end

#resumeObject



54
55
56
57
58
59
# File 'app/controllers/telephony/conversations_controller.rb', line 54

def resume
  lock_conversation(params['id'], 'Resume failed. Please try again in a few seconds.') do |conversation|
    conversation.resume!
    render json: {}
  end
end

#searchObject



16
17
18
19
20
21
22
23
# File 'app/controllers/telephony/conversations_controller.rb', line 16

def search
  conversations = ConversationData.search params
  conversations_presenter = ConversationsPresenter.new conversations
  render json: {
    total_count: conversations.total_count,
    conversations: conversations_presenter
  }
end

#updateObject



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

def update
  Conversation.find_with_lock params[:id] do |conversation|
    conversation.update_attributes loan_id: params[:loan_id]
    render json: conversation
  end
end