From 9d8e6b4ae1e437fb4e02041d4bf7040678b22f77 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 8 Feb 2022 20:35:46 -0500 Subject: [PATCH] Pass customer_id through to leg2 The to in leg2 is not the phone number, but the fwd, which is not useful for looking up customer. --- test/test_web.rb | 24 ++++++++++++++++-------- views/inbound/at_limit.slim | 2 +- web.rb | 14 +++++++++----- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/test/test_web.rb b/test/test_web.rb index 3856ff9..00fa423 100644 --- a/test/test_web.rb +++ b/test/test_web.rb @@ -264,7 +264,13 @@ class WebTest < Minitest::Test OpenStruct.new(data: OpenStruct.new(call_id: "ocall")), [ "test_bw_account", - Matching.new { |arg| assert_equal [:body], arg.keys } + Matching.new do |arg| + assert_equal( + "http://example.org/inbound/calls/acall?customer_id=customerid", + arg[:body].answer_url + ) + assert_equal [:body], arg.keys + end ] ) @@ -320,10 +326,10 @@ class WebTest < Minitest::Test def test_inbound_leg2 post( - "/inbound/calls/acall", + "/inbound/calls/acall?customer_id=customerid", { from: "+15557654321", - to: "+15551234567", + to: "sip:boop@example.com", callId: "ocall" }.to_json, { "CONTENT_TYPE" => "application/json" } @@ -340,11 +346,13 @@ class WebTest < Minitest::Test em :test_inbound_leg2 def test_inbound_limit_leg2 + path = "/inbound/calls/acall?customer_id=customerid_limit" + post( - "/inbound/calls/acall", + path, { from: "+15557654321", - to: "+15551234561", + to: "sip:boop@example.com", callId: "ocall" }.to_json, { "CONTENT_TYPE" => "application/json" } @@ -353,7 +361,7 @@ class WebTest < Minitest::Test assert last_response.ok? assert_equal( "" \ - "This call will take you over " \ "your configured monthly overage limit." \ "Change your limit in your account settings or press 1 to accept the " \ @@ -366,10 +374,10 @@ class WebTest < Minitest::Test def test_inbound_limit_digits_leg2 post( - "/inbound/calls/acall", + "/inbound/calls/acall?customer_id=customerid_limit", { from: "+15557654321", - to: "+15551234561", + to: "sip:boop@example.com", callId: "ocall", digits: "1" }.to_json, diff --git a/views/inbound/at_limit.slim b/views/inbound/at_limit.slim index 44b1d24..48068db 100644 --- a/views/inbound/at_limit.slim +++ b/views/inbound/at_limit.slim @@ -1,5 +1,5 @@ doctype xml Response - Gather gatherUrl="/inbound/calls/#{call_id}" maxDigits="1" repeatCount="3" + Gather gatherUrl="/inbound/calls/#{call_id}?customer_id=#{customer_id}" maxDigits="1" repeatCount="3" SpeakSentence This call will take you over your configured monthly overage limit. SpeakSentence Change your limit in your account settings or press 1 to accept the charges. You can hang up to send the caller to voicemail. diff --git a/web.rb b/web.rb index 53f73ec..947ec65 100644 --- a/web.rb +++ b/web.rb @@ -134,8 +134,9 @@ class Web < Roda ) end - def inbound_calls_path(suffix) - ["/inbound/calls/#{params['callId']}", suffix].compact.join("/") + def inbound_calls_path(suffix, customer_id=nil) + ["/inbound/calls/#{params['callId']}", suffix].compact.join("/") + + (customer_id ? "?customer_id=#{customer_id}" : "") end def url(path) @@ -245,7 +246,9 @@ class Web < Roda end r.post do - customer_repo.find_by_tel(params["to"]).then do |customer| + customer_repo( + sgx_repo: Bwmsgsv2Repo.new + ).find(params.fetch("customer_id")).then do |customer| call_attempt_repo.find_inbound( customer, params["from"], @@ -261,17 +264,18 @@ class Web < Roda sgx_repo: Bwmsgsv2Repo.new ).find_by_tel(params["to"]).then { |customer| EMPromise.all([ + customer.customer_id, customer.fwd, call_attempt_repo.find_inbound( customer, params["from"], call_id: params["callId"] ) ]) - }.then do |(fwd, ca)| + }.then do |(customer_id, fwd, ca)| call = ca.create_call(fwd, CONFIG[:creds][:account]) { |cc| cc.from = params["from"] cc.application_id = params["applicationId"] - cc.answer_url = url inbound_calls_path(nil) + cc.answer_url = url inbound_calls_path(nil, customer_id) cc.disconnect_url = url inbound_calls_path(:transfer_complete) } -- 2.45.2