I had this question after viewing
Looking for a new SMS provider for my PowerBuilder application.
I have been using Twilio's SMS messaging service since I originally asked the question I'm referencing. Now my issue is that my corporate client is requiring that I deploy my application on their internal network and servers. While my PowerBuilder code which has worked fine while running on my own server, fails to send text messages when deployed on the corporate servers, specifically because they block access to the internet and the only solution they've suggested would require the use of their PROXY server. I know NOTHING about proxy servers and I'm looking for some help in making the required program changes to be able to utilize a proxy server to permit access to Twilio (api.twilio.com) in order to maintain this feature in my application which has become very popular with my users.
So, besides the PowerBuilder powerscript code, I had to incorporate a third party's APIs (Chilkat Software) in order to send the SMS messages. My existing code follows:
loo_Glob = create oleobject
li_rc = loo_Glob.ConnectToNewObjec
t( struct_1.tw_global_object )
if li_rc < 0 then
as_response = "Connect to New GLOB Object Error: " + loo_Rest.LastErrorText
wf_send_warning_email( as_response )
destroy loo_Glob
return false
end if
li_Success = loo_Glob.UnlockBundle( struct_1.tw_global_unlock )
if li_Success <> 1 then
as_response = "GLOB Unlock Bundle Error: " + loo_Rest.LastErrorText
wf_send_warning_email( as_response )
destroy loo_Glob
return false
end if
li_Status = loo_Glob.UnlockStatus
destroy loo_Glob
// Demonstrates how to use Basic Authentication in a REST API call for Twilio.
// Sends an SMS text message..
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Rest = Create oleobject
li_rc = loo_Rest.ConnectToNewObjec
t(struct_1
.tw_rest_o
bject)
if li_rc < 0 then
as_response = "Connect to New REST Object Error: " + loo_Rest.LastErrorText
wf_send_warning_email( as_response )
destroy loo_Rest
return false
end if
// Use Basic Authentication.
// Your Twilio Account SID is the username.
// Your Twilio Auth Token is the password.
li_Success = loo_Rest.SetAuthBasic( ls_LiveAcctSID,ls_LiveAuth
Token)
If gb_show_debug_msgs = TRUE then
li_Success = loo_Rest.SetAuthBasic( ls_TestAcctSID,ls_TestAuth
Token)
End If
// Make the initial connection (without sending a request yet) to Twilio.
li_BTls = struct_1.tw_connect_bti
li_Port = struct_1.tw_connect_port
li_BAutoReconnect = struct_1.tw_auto_reconnect
li_Success = loo_Rest.Connect( struct_1.tw_rest_url, li_Port, li_BTls, li_BAutoReconnect)
if li_Success <> 1 then
as_response = "Connect to Twilio FAILED... " + "~h0A~h0D"
as_response = as_response + " Twilio Connect URL: " + struct_1.tw_rest_url + "~h0A~h0D"
as_response = as_response + " Twilio Connect BTI: " + String(li_BTls) + "~h0A~h0D"
as_response = as_response + " Twilio Connect Port: " + String(li_Port) + "~h0A~h0D"
as_response = as_response + " Twilio AutoReconnect: " + String(li_Port) + "~h0A~h0D"
as_response = as_response + " Twilio Connect Success Return Code: " + String(li_BAutoReconnect) + "~h0A~h0D"
as_response = as_response + " Error Text: " + loo_Rest.LastErrorText
wf_send_warning_email( as_response )
destroy loo_Rest
return false
end if
// Provide the information for the SMS text message:
li_Success = loo_Rest.AddQueryParam( "To", as_PhoneNbr )
li_Success = loo_Rest.AddQueryParam( "From", is_From )
li_Success = loo_Rest.AddQueryParam( "Body", as_message )
//li_Success = loo_Rest.AddQueryParam( "AlphaSender", "OVERTIME" ) //Not available in USA....
// Send the SMS text message.
// Your Twilio Account SID is part of the URI path:
If gb_show_debug_msgs = TRUE then
ls_ResponseJson = loo_Rest.FullRequestFormUr
lEncoded( struct_1.tw_test_rest_cmd,
struct_1.tw_test_rest_url )
Else
ls_ResponseJson = loo_Rest.FullRequestFormUr
lEncoded( struct_1.tw_live_rest_cmd,
struct_1.tw_live_rest_url )
End If
if loo_Rest.LastMethodSuccess
<> 1 then
as_response = "Send Error: " + loo_Rest.LastErrorText
wf_send_warning_email( as_response )
destroy loo_Rest
return false
end if
// When successful, the response status code will equal 201.
if loo_Rest.ResponseStatusCod
e <> 201 then
as_response = "Response Status NOT equal to 201... " + "~h0A~h0D"
as_response = as_response + " Target Phone Number: " + as_phoneNbr + "~h0A~h0D"
as_response = as_response + " Department: " + g_name + "~h0A~h0D"
as_response = as_response + " Employee: " + Trim(txtmsg_firstname) + " " + Trim(txtmsg_mi) + " " + Trim(txtmsg_lastname) + "~h0A~h0D"
as_response = as_response + " Error Text: " + loo_Rest.LastErrorText
wf_send_warning_email( as_response )
destroy loo_Rest
return false
end if
Any "struct_1" references in the code represent values that I maintain in a SQL Server database. All the "Chilkat-specific" calls work until the call that actually attempts to "Send the SMS text message" (reference that wording in the commented code above).
As always any help would be greatly appreciated....and anyone else who works with the Twilio service and needs to utilize a "proxy server" (whether or not you're using PowerBuilder), I suspect could provide valuable insight into my current situation. TIA, Jim Klocksin
Best option, since you already have working code, is for your client to open a path through their firewall to Twilio, which should be trivial.
Since https://api.twilio.com provides the interface, the related firewall rule will be to simply open port 80 + port 443.
If this can't be done, then likely this company already runs SOCKS or some other proxy system.
Said another way, only a person with admin privilege inside this company can setup + run a proxy.
So your first hurdle to "setup some proxy on your own" will be to have this company make you a global admin for all the systems between the machine running your code + the public Internet.
Possible Alternative: A possible work around would be for you to create an SMTP -> https://api.twilio.com system, which converts email messages into Twilio API calls.
My guess is this would be fairly easy. Just make sure you run this server as authenticated (user/pass login required) port 587 submission for email, else you run the risk of random people sending SMS messages by hammering your mail server port 25 with bogus messages.