@@ -205,15 +205,15 @@ class Web < Roda
])
end
- def create_call(customer, from, call_id, application_id)
+ def create_call(customer, from, call_id, application_id, tries: nil)
call_inputs(customer, from, call_id).then do |(customer_id, fwd, ca)|
ca.create_call(fwd, CONFIG[:creds][:account]) do |cc|
cc.from = from
cc.application_id = application_id
cc.answer_url = url inbound_calls_path(nil, customer_id)
cc.disconnect_url = url(
- inbound_calls_path(:transfer_complete, customer_id)
- )
+ inbound_calls_path(:transfer_complete, customer_id, call_id: call_id)
+ ) + (tries ? "&tries=#{tries}" : "")
end
end
end
@@ -248,6 +248,17 @@ class Web < Roda
modify_call(call_id) { |call| call.state = "completed" }
elsif !outbound_leg
log.debug "Inbound disconnected", loggable_params
+ elsif params["cause"] == "error" && params["tries"].to_i < 15
+ log.info "2nd leg error, retry", loggable_params
+ create_call(
+ customer,
+ params["from"],
+ call_id,
+ params["applicationId"],
+ tries: params["tries"].to_i + 1
+ ).then { |call|
+ outbound_transfers[params["callId"]] = call
+ }.catch(&log.method(:error))
else
log.debug "Go to voicemail", loggable_params
modify_call(call_id) do |call|