M test/test_web.rb => test/test_web.rb +16 -8
@@ 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(
"<?xml version=\"1.0\" encoding=\"utf-8\" ?><Response>" \
- "<Gather gatherUrl=\"\/inbound/calls/acall\" maxDigits=\"1\" " \
+ "<Gather gatherUrl=\"#{path}\" maxDigits=\"1\" " \
"repeatCount=\"3\"><SpeakSentence>This call will take you over " \
"your configured monthly overage limit.</SpeakSentence><SpeakSentence>" \
"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,
M views/inbound/at_limit.slim => views/inbound/at_limit.slim +1 -1
@@ 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.
M web.rb => web.rb +9 -5
@@ 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)
}