When you are developing some cool telephony apps using Exotel APIs or building some kickass flow logic for incoming calls using the powerful app builder, you would like a quick and easy way to test out your StatusCallback and Passthru URLs. One pain point for most developers during development is to find a publicly available server, deploy your code there and test it out. You would rather test it right on your localbox, make changes, test, rinse, repeat. It’s a nightmare to develop your code on the server, or keep copying over your code from your localbox to the server for every iteration. ngrok addresses this very problem, letting you develop on your localbox and exposing your local endpoints on a publicly available address. It creates a secure tunnel to your localhost and provides you with a public URL. Any access to that URL gets routed to your local machine. Using ngrok you can test your code right on your computer and keep making changes to it. This will increase the speed at which you can develop your Exotel application.
STEP 1 – Install ngrok
To install ngrok on your box, all you need to do is download it from here and unzip it. You could add the location of the installation to your path if you are on a *nix machine
Step 2 – Get your endpoint ready
I’m assuming you have a web server running already on your local machine. What we will do is implement a statuscallback at the end of a call, originated using the exotel API. So here is a simple endpoint which does nothing but log the variables passed by Exotel at the end of the call to the statuscallback URL.
Step 3 – Start ngrok
We are all set to make this endpoint available to the world. Start ngrok
$ ./ngrok http 80
The above command assumes your http server is running on the default port 80. Change the port number if that is not the case.
You would get a output like below
ngrok by @inconshreveable (Ctrl + C to quit) Tunnel Status online Version 2.0.19/2.0.19 Web Interface http://127.0.0.1:4040 Forwarding http://4ee2ddec.ngrok.io localhost:80 Forwarding https://4ee2ddec.ngrok.io localhost:80 Connections ttl opn rt1 rt5 p50 p90 0 0 0.00 0.00 0.00 0.00
So http://4ee2ddec.ngrok.io and https://4ee2ddec.ngrok.io are the public addresses than you can use. If you point your browser to either of the two, it will take you to the default page on your localhost served by the webserver.
(Pro-Tip : Goto http://localhost:4040 . It has detailed logs of all the requests & responses on the ngrok URL)
(Useless-Tip : ngrok is written in GoLang)
Step 4 – Start using these Public URLs
The statuscallback URL that we wrote in step 3 is now available at localhost/statuscallback.php. The public address for this is https://4ee2ddec.ngrok.io/statuscallback.php.
I’m going to go ahead and invoke the Exotel API to make a call and pass this as the StatusCallback URL. This URL will be hit at the end of the call. You can go grab a sample code to invoke a call from here.
This is the POST parameters I send to the Call API
$post_data = array('From' = "xxxxxxxxxx", 'To' = "yyyyyyyyyy", 'CallerId' = zzzzzzzzzzz", 'CallType' = "trans", //Can be "trans" for transactional and "promo" for promotional content 'StatusCallBack' = "https://4ee2ddec.ngrok.io/statuscb.php" );
Once the call ends you would see something in your webserver’s error logs
[Wed Oct 07 15:29:27.997482 2015] [:error] [pid 2113] [client 127.0.0.1:53689] Status Callback invoked [Wed Oct 07 15:29:27.997604 2015] [:error] [pid 2113] [client 127.0.0.1:53689] Arrayn(n [CallSid] = 2**************************6fn [Status] = completedn [RecordingUrl] = https://s3-ap-southeast-1.amazonaws.com/exotelrecordings/******/2***************.mp3n [DateUpdated] = 2015-10-07 15:29:27n)n
(Some of the details have been masked out)
And that’s it, you are all ready to make changes and develop your application at a blazing speed, right on your localbox. Go ahead, integrate exotel into your applications much faster. And thank ngrok.