Class: Telephony::InboundConversationQueue
- Inherits:
-
Object
- Object
- Telephony::InboundConversationQueue
- Defined in:
- app/models/telephony/inbound_conversation_queue.rb
Class Method Summary collapse
- .dequeue(csr_id) ⇒ Object
- .oldest_queued_conversation ⇒ Object
- .play_closed_greeting(args) ⇒ Object
- .play_message(args) ⇒ Object
- .reject(args) ⇒ Object
Class Method Details
.dequeue(csr_id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/telephony/inbound_conversation_queue.rb', line 33 def self.dequeue(csr_id) with_agent_on_a_call(csr_id) do |agent| begin conversation = oldest_queued_conversation if conversation agent_call = conversation.calls.create! number: agent.phone_number, agent: agent agent_call.connect! conversation.customer.redirect_to_inbound_connect csr_id pop_url = Telephony.pop_url_finder && Telephony.pop_url_finder.find(conversation.customer.sanitized_number) { id: conversation.id, customer_number: conversation.customer.number, pop_url: pop_url } else raise Telephony::Error::QueueEmpty.new end rescue Telephony::Error::NotInProgress agent_call.destroy conversation.customer.terminate! retry end end end |
.oldest_queued_conversation ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/telephony/inbound_conversation_queue.rb', line 63 def self.oldest_queued_conversation Conversation.transaction do conversation = Conversation .where(state: 'enqueued') .order(:created_at) .lock(true) .first conversation.connect! if conversation conversation end end |
.play_closed_greeting(args) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'app/models/telephony/inbound_conversation_queue.rb', line 14 def self.play_closed_greeting(args) Conversation.transaction do conversation = Conversation.create_inbound! number: args[:To], caller_id: args[:To] conversation.play_closed_greeting! customer_leg = conversation.calls.create! number: args[:From], sid: args[:CallSid] customer_leg.terminate! conversation end end |
.play_message(args) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'app/models/telephony/inbound_conversation_queue.rb', line 3 def self.(args) Conversation.transaction do conversation = Conversation.create_inbound! number: args[:To], caller_id: args[:To] conversation. customer_leg = conversation.calls.create! number: args[:From], sid: args[:CallSid] customer_leg.connect! customer_leg.answer! conversation end end |
.reject(args) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'app/models/telephony/inbound_conversation_queue.rb', line 24 def self.reject(args) Conversation.transaction do conversation = Conversation.create_inbound! number: args[:To], caller_id: args[:To] customer_leg = conversation.calls.create! number: args[:From], sid: args[:CallSid] customer_leg.reject! conversation end end |