From 90a21bc734fabb8d576ecb4c5d46ae2f34a1a1d3 Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Tue, 5 May 2020 23:13:17 +0000 Subject: [PATCH] prepare SGX for use with jmp-fwdcalls, which is V1 Until Bandwidth supports SIP endpoints in their V2 voice API, we need to use their V1 voice API. However, to use the V1 voice API alongside the V2 messages API, we need to be a bit clever. In particular, we need to detect when we're getting a V1 call and adjust the URL accordingly. The hack implemented here to accomplish this allows us to make very minimal changes to jmp-fwdcalls (letting it continue to use an unmodified call_catapult() invocation) while still permitting it to work with the V2 SGX (this one) as well as the V1 SGX. As noted in this commit's comments, jmp-fwdcalls will need to pass us some V1 credentials to use (since the V2 user won't have these available in its creds list). But that should be the only added complexity here. --- sgx-bwmsgsv2.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sgx-bwmsgsv2.rb b/sgx-bwmsgsv2.rb index 7552eb108b87e1f0a2a430c65f36dd21c8b6de9a..b602001eeb5c59c8b7f468fd27a4420d22d5437c 100755 --- a/sgx-bwmsgsv2.rb +++ b/sgx-bwmsgsv2.rb @@ -200,9 +200,25 @@ module SGXbwmsgsv2 token, secret, m, pth, body=nil, head={}, code=[200], respond_with=:body ) + # pth looks like one of: + # "api/v2/users/#{user_id}/[endpoint_name]" + # "v1/users/#{user_id}/[endpoint_name]" + + url_prefix = '' + # TODO: need to make a separate thing for voice.bw.c eventually + if pth.start_with? 'api/v2/users' + url_prefix = 'https://messaging.bandwidth.com/' + elsif pth.start_with? 'v1/users' + # begin hack for running V2 messages along with V1 voice + url_prefix = 'https://api.catapult.inetwork.com/' + # TODO: set token and secret to vals provided at startup + else + # TODO: error + end + EM::HttpRequest.new( - "https://messaging.bandwidth.com/#{pth}" + url_prefix + pth ).public_send( m, head: {