Say, you are an entrepreneur or the marketing head of an organization and your main source of leads are phone calls. To spend your marketing dollars wisely, you will have to know which of your campaigns generate the maximum number of calls. This can be done using a call tracking system.
Call tracking systems these days are usually very expensive and cumbersome. In this blog, we would like to explain stepwise an easy call tracking system that combines the powers of twilio and google analytics to give you a very detailed picture of the calls and locations of these calls.
Step 1: Create a new google analytics account and Twilio call Forward Function
Now, go to google analytics (www.google.com/analytics), sign in to create a new account. For this,
Go to Admin->create account-> give the specification for website tracking. In the required column enter any website name and url(for example, www.example.com), also select the category as industry. To get the Tracking Id Go to Admin -> property ->Property Settings->you can now see the Tracking ID. This tracking id is needed to connect your twilio function and google analytics so it should be noted.
Log in to your Twilio account(www.twilio.com) go to Runtime, Select “Function”, and then click “+” symbol and select “Call forward function” and hit create(to create a new call forward function).
Open the function and give the function name and the path as your choice. This function path is needed later so, copy this path and save the function.
Step 2: Attaching the Twilio Function to their Twilio Number and Tracking Id
Go to Phone Numbers(# in menu) in your Twilio account and select your twilio number from the list of active numbers. If you don’t have a number, buy a number and then go to Phone Numbers(# in menu) and select the number from the list of active numbers. After selecting the number, go to Voice & Fax
option and select Voice calls. In the “A CALL COMES IN” box, set it as webhook and provide the details in the empty box beside it, in the following format:
Paste your function path?PhoneNumber=(here set the actual phone number which you need to be forward all the calls. Remove the spaces and hyphens in the number)&campaign=(here set campaign name of the number you have currently selected))&trackingId=(here set the tracking Id you got from google analytics)
For example,
https://glorious-front-7473.twil.io/callforward?PhoneNumber=+19876543210&campaign=abc_business&trackingId=UA-123456789-1
Don’t forget to save these changes.
You can change the Phone numbers for different campaign for the same trackingId.
Go back to Runtime ->Go to Twilio function and Create Another blank function Similarly, that you have created for call forward function. Give the function name as Call Action
and path as /call_action
and save the function.
Step 3: Call Forward function.
Go back to the call forward function. This function is used to forward calls that are received by your twilio campaign numbers to the actual phone number of your business through Webhook(HTTP post). The call forward function accepts two parameters i.e., campaign and actual phone number. Paste the following code in the box provided and save the function.
Here is the code for Call Forward function
exports.handler = function(context, event, callback) { let phoneNumber = event.PhoneNumber; let campaign = event.campaign; let trackingId = event.trackingId; let domain = context.DOMAIN_NAME; let twiml = new Twilio.twiml.VoiceResponse(); let allowedThrough = true; //Checking campaign is given or not. If there is no campaign_name the call is not forwarding to another number if (campaign === null) { allowedThrough = false; } let dialParams = {}; if (campaign) { dialParams.campaign = campaign; } var actionUrl ='https://'+domain+'/call_action?PhoneNumber='+phoneNumber+'&campaign='+campaign+'&trackingId='+trackingId; if (allowedThrough) { twiml.dial( { action :encodeURI(actionUrl), method:'GET' },phoneNumber ); } else { twiml.say('Sorry, you are calling from a restricted number. Good bye.'); } // return the TwiML callback(null, twiml); };
Step 4: Linking the system with google analytics
Go back to the Call Action function and paste the following code in the box provided and save the function.
Here is the code for updating events API,
exports.handler = function(context, event, callback) { var http = require('http'); const analyticsID = event.trackingId; const gaUrl = "http://www.google-analytics.com/collect?v=1&t=event&tid="+analyticsID+"&"; function sendAnalyticsEvent(eventParams,callback) { var url = gaUrl+eventParams; http.get(url, function(res) { if(res.statusCode === 200){ console.log("Sent event: status="+res.statusCode+", params", eventParams); let twiml = new Twilio.twiml.VoiceResponse(); twiml.hangup(); callback(null, twiml); } }).on('error', function(e) { console.log("Sent event: error="+e.message+", params", eventParams); let twiml = new Twilio.twiml.VoiceResponse(); twiml.say('Sorry, there is an error in reporting analyitics. Good bye.'); callback(null, twiml); }); } var callerGeoDetail = GeoCode(event.From); var callerGeoCode = callerGeoDetail["code"]; var contact = event.From; var Duration = event.DialCallDuration; var CallStatus = event.DialCallStatus; if(Duration === undefined){ Duration=0;} var eventParams = "ec=Call&ea="+CallStatus+"&ev="+Duration+"&el="+event.campaign+"&t=event&v=1&cid="+contact; eventParams += "&geoid="+callerGeoCode; sendAnalyticsEvent(eventParams,callback); }; function GeoCode(number) { var _4DigitgeoCodeMapping = get4DigitGeoCodeMapping(); var _3DigitgeoCodeMapping = get3DigitGeoCodeMapping(); var _2DigitgeoCodeMapping = get2DigitGeoCodeMapping(); var _1DigitgeoCodeMapping = get1DigitGeoCodeMapping(); var get4DigitCallingCode = number.substring(1, 5); var get3DigitCallingCode = number.substring(1, 4); var get2DigitCallingCode = number.substring(1, 3); var get1DigitCallingCode = number.substring(1, 2); var geoCode = _4DigitgeoCodeMapping[get4DigitCallingCode] || _3DigitgeoCodeMapping[get3DigitCallingCode] || _2DigitgeoCodeMapping[get2DigitCallingCode] || _1DigitgeoCodeMapping[get1DigitCallingCode] || "2270"; console.log("geoCode",geoCode); if(geoCode == "20117")// mapping of area code for canadian number. { var areaCodeToGeoCodeMapping = getAreaCodeToGeoCodeMapping(); var areaCode = number.substring(2, 5); var geoAreaCode = areaCodeToGeoCodeMapping[areaCode] || "20117"; var geoAreaDetails = {"code": geoAreaCode}; console.log("geoDetails",geoAreaDetails); return geoAreaDetails; } else{ var geoDetails = {"code": geoCode}; console.log("geoDetails",geoDetails); return geoDetails; } } function get4DigitGeoCodeMapping(){ return{ "1473":"21137","1671":"2316","1876":"2388","1664":"2500","1670":"2580","1787":"2630","1939":"2630","1869":"2659","1758":"2662","1784":"2670","1868":"2780","1649":"2796","1284":"2850","1340":"2850","1684":"2882","1264":"2660","1268":"2028","1242":"2044","1246":"2052","1441":"2060","1345":"2136","1767":"2212","1809":"2212","1828":"2212","1849":"2212" }; } function get3DigitGeoCodeMapping(){ return{ "355":"2008","213":"2012","376":"2020","244":"2024","374":"21519","297":"2533","994":"2031","973":"2048","880":"2050","375":"2112","501":"2084","229":"2204","975":"2064","591":"2068","387":"2070","267":"2072","673":"2096","359":"2100","226":"2854","257":"2108","855":"2116","237":"2120","238":"2132","236":"2140","235":"2148","618":"2162","269":"2174","242":"2178","243":"2180","682":"2184","506":"2188","225":"2430","385":"2191","357":"2196","420":"2203","253":"2262","593":"20264","503":"2222","240":"2226","291":"2232","372":"2233","251":"2231","500":"2238","298":"2234","679":"2242","358":"2246","594":"2254","689":"2258","241":"2266","220":"2270","995":"2268","233":"2288","350":"2292","299":"2304","590":"2312","502":"2320","224":"2324","245":"2324","592":"2328","509":"2332","379":"2336","504":"2340","852":"2344","354":"2352","964":"2368","353":"2372","972":"2376","962":"2400","254":"2404","686":"2296","850":"21331","965":"2414","996":"2417","856":"2418","371":"2428","961":"2422","266":"2426","231":"2430","218":"2434","423":"2438","370":"2440","352":"2442","853":"2446","389":"2807","261":"2450","265":"2454","960":"2462","223":"2466","356":"2470","692":"2584","596":"2474","222":"2478","230":"2480","262":"2175","691":"2583","373":"2498","377":"2492","976":"20167","382":"2499","212":"2504","258":"2508","264":"2516","674":"2520","977":"2524","599":"2530","687":"2540","505":"2558","227":"2562","234":"2566","683":"2570","672":"2574","968":"2512","680":"2585","970":"2376","507":"21142","675":"2598","595":"2600","870":"2612","351":"2620","974":"2634","250":"2646","290":"2682","508":"2666","685":"2882","378":"21137","239":"2678","966":"2682","221":"2686","381":"2688","248":"2690","232":"2694","421":"2703","386":"2705","677":"2090","252":"2706","249":"21176","597":"2740","268":"2748","963":"2368","886":"2158","992":"2762","255":"2834","670":"2626","228":"2768","690":"2772","676":"2776","216":"2788","993":"2795","688":"2798","256":"2800","380":"2804","971":"2784","598":"2858","998":"2860","678":"2548","681":"2876","967":"2887","260":"2894","263":"2716" }; } function get2DigitGeoCodeMapping(){ return{ "93":"2004","54":"20008","61":"20035","43":"20048","32":"2056","55":"20088","57":"20114","53":"21147","45":"21154","20":"21164","33":"20332","49":"20235","30":"2300","36":"2348","91":"2356","62":"2360","98":"2368","81":"20624","76":"2398","77":"2398","82":"21331","60":"20737","52":"21142","31":"2528","64":"2554","92":"2586","51":"2604","63":"2608","48":"20862","40":"21244","65":"2702","27":"21222","34":"20282","94":"2144","47":"2744","46":"21014","41":"20133","66":"21044","90":"21354","44":"20339","58":"21204","84":"21044" }; } function get1DigitGeoCodeMapping(){ return{ "1":"20117","7":"20931" }; } function getAreaCodeToGeoCodeMapping() { return { "907": "21132", "205": "21133", "251": "21133", "256": "21133", "334": "21133", "479": "21135", "501": "21135", "870": "21135", "480": "21136", "520": "21136", "602": "21136", "623": "21136", "928": "21136", "209": "21137", "213": "21137", "310": "21137", "323": "21137", "408": "21137", "415": "21137", "424": "21137", "510": "21137", "530": "21137", "559": "21137", "562": "21137", "619": "21137", "626": "21137", "650": "21137", "661": "21137", "707": "21137", "714": "21137", "760": "21137", "805": "21137", "818": "21137", "831": "21137", "858": "21137", "909": "21137", "916": "21137", "925": "21137", "949": "21137", "303": "21138", "719": "21138", "720": "21138", "970": "21138", "203": "21139", "475": "21139", "860": "21139", "959": "21139", "202": "21140", "302": "21141", "239": "21142", "305": "21142", "321": "21142", "352": "21142", "386": "21142", "407":"21142", "561": "21142", "727": "21142", "754": "21142", "772": "21142", "786": "21142", "813": "21142", "850": "21142", "863": "21142", "904": "21142", "941": "21142", "954": "21142", "229": "21143", "404": "21143", "470": "21143", "478": "21143", "678": "21143", "706": "21143", "770": "21143", "912": "21143", "808": "21144", "319": "21145", "515": "21145", "563": "21145", "641": "21145", "712": "21145", "208": "21146", "217": "21147", "224": "21147", "309": "21147", "312": "21147", "331": "21147", "464": "21147", "618": "21147", "630": "21147", "708": "21147", "773": "21147", "815": "21147", "847": "21147", "872": "21147", "219": "21148", "260": "21148", "317": "21148", "574": "21148", "765": "21148", "812": "21148", "316": "21149", "620": "21149", "785": "21149", "913": "21149", "270": "21150", "502": "21150", "606": "21150", "859": "21150", "225": "21151", "318": "21151", "337": "21151", "504": "21151", "985": "21151", "339": "21152", "351": "21152", "413": "21152", "508": "21152", "617": "21152", "774": "21152", "781": "21152", "857": "21152", "978": "21152", "227": "21153", "240": "21153", "301": "21153", "410": "21153", "443": "21153", "667": "21153", "207": "21154", "231": "21155", "248": "21155", "269": "21155", "313": "21155", "517": "21155", "586": "21155", "616": "21155", "734": "21155", "810": "21155", "906": "21155", "947": "21155", "989": "21155", "218": "21156", "320": "21156", "507": "21156", "612": "21156", "651": "21156", "763": "21156", "952": "21156", "314": "21157", "417": "21157", "557": "21157", "573": "21157", "636": "21157", "660": "21157", "816": "21157", "975": "21157", "228": "21158", "601": "21158", "662": "21158", "406": "21159", "252": "21160", "336": "21160", "704": "21160", "828": "21160", "910": "21160", "919": "21160", "980": "21160", "984": "21160", "701": "21161", "308": "21162", "402": "21162", "603": "21163", "201": "21164", "551": "21164", "609": "21164", "732": "21164", "848": "21164", "856": "21164", "862": "21164", "908": "21164", "973": "21164", "505": "21165", "702": "21166", "775": "21166", "212": "21167", "315": "21167", "347": "21167", "516": "21167", "518": "21167", "585": "21167", "607": "21167", "631": "21167", "646": "21167", "716": "21167", "718": "21167", "845": "21167", "914": "21167", "917": "21167", "216": "21168", "234": "21168", "283": "21168", "330": "21168", "419": "21168", "440": "21168", "513": "21168", "567": "21168", "614": "21168", "740": "21168", "937": "21168", "405": "21169", "580": "21169", "918": "21169", "503": "21170", "541": "21170", "971": "21170", "215": "21171", "267": "21171", "412": "21171", "445": "21171", "484": "21171", "570": "21171", "610": "21171", "717": "21171", "724": "21171", "814": "21171", "835": "21171", "878": "21171", "401": "21172", "803": "21173", "843": "21173", "864": "21173", "605": "21174", "423": "21175", "615": "21175", "731": "21175", "865": "21175", "901": "21175", "931": "21175", "210": "21176", "214": "21176", "254": "21176", "281": "21176", "361": "21176", "409": "21176", "469": "21176", "512": "21176", "682": "21176", "713": "21176", "737": "21176", "806": "21176", "817": "21176", "830": "21176", "832": "21176", "903": "21176", "915": "21176", "936": "21176", "940": "21176", "956": "21176", "972": "21176", "979": "21176", "435": "21177", "801": "21177", "276": "21178", "434": "21178", "540": "21178", "571": "21178", "703": "21178", "757": "21178", "804": "21178", "802": "21179", "206": "21180", "253": "21180", "360": "21180", "425": "21180", "509": "21180", "564": "21180", "262": "21182", "414": "21182", "608": "21182", "715": "21182", "920": "21182", "304": "21183", "307": "21184" }; }
Note: Call are tagged at the country level. However, calls from US and Canada are further resolved to the state or province in Google Analytics. Calls from any unknown country are marked as Gambia.
After completing these steps, you can test it by calling to the twilio number you have setup.
The results can be viewed in the google analytics account you had created in step 1.
Login to google analytics account that you have created for call tracking. Go to real-time, select events there you can see the live results of call tracking as given in the below figure..
To see the location of the caller. Go to Audience -> geo -> location.
To see the accumulated results of the call tracking,
Go to Behaviour ->Events->Overview
This Overview represents the call tracking data over a month. The present day details are noted in real-time->events.
You can select the range of the days at the right top of your window.
1. Total events : Total number of calls.
2. Unique events : Total number of unique calls.
3. Event value : total call duration for all calls.
4. Average value : Average call duration.
To see the results for different campaign. Click “Event Label” to choose campaign.
To know Calls Status. Click “Event action”.
Thus, using twilio call tracking function,you can get a clear picture of the impact of your marketing efforts on lead generation and sales and you can also make your campaigns more effective and cost efficient based on these results.
Fax is a traditional technology. However, it still is an essential tool for a variety of organizations – from hospitals to law offices, from pizza shops to the offices of the Federal Bureau of Investigation . Traditionally Fax required a machine, was offline and brittle. Today, it’s online and ready to work for you. Twilioid allows you to send fax from a fax capable twilio number to a traditional fax machine. It is also possible receive FAX from a fax machine to a twilio number. FAX between two Twilio numbers is also supported.
In this Blog, first we will demonstrate how to set up a twilio fax number then how to send and receive faxes in twilioid between twilio numbers and fax machines.
After signing in to your twilioid account, you can set an existing number in your twilio account as your fax number if the number is fax capable. Alternatively, you can buy and add a new fax number to your account.
If you have fax supported twilio numbers, you can set any one of these numbers as your fax number.
Only fax capable numbers will be listed in Fax list. You can select the number which you want and set it as your fax number by clicking “Set Number” button. One thing should be noted, same number cannot be used for both voice and fax. When you set a fax number to receive fax , number will be unavailable to receive calls. Alternatively you can also set fax number in your twilio account console and link it with the fax url “https://twilioid.com/fax-twiml.php”.
If you do not have a twilio number which is capable of sending and receiving faxes, you can buy and add a new one to your account.
1.You can search numbers by providing country name and an optional area code then clicking the “Search” button. Here, the most important thing is to be noted that you must ensure that the fax capability field is checked instead of the voice.
2.Once the search is finished, available numbers with the given requirements will be shown. Now you can purchase a number from the list which you liked most by clicking the “Buy&Set” button. You can purchase number from your twilio account console and link it with the fax url “https://twilioid.com/fax-twiml.php”.
Once you have completed the setup process, Your current fax number will be shown in the fax number field. You may check it to ensure that your fax number is set.
After setting up your fax number, you can login to your web twilioid account and send fax to a fax machine or another twilio number which is capable of receiving fax.
1.In your home page you can see a button labelled as “Send Fax”. Click that button and a window will be opened.
2.Fill the recipient number.
3.Browse the file which you want to send. Currently we support PDF files only.
4.After completing above two steps, click the “Send Fax” button to send fax.
Within moments, your fax should be happily on its way to a lucky recipient. You can also use the “Use Online PDF Converter” link for converting your file to PDF file format.
You can also view all inbound faxes received in your fax enabled number and reply to those faxes from your twilioid account.
1.In your home page you can see a button labelled as “View Fax”. Click that button and now a window will be opened before you. Here you can download all incoming faxes and reply.
2.Click the “Download” button to view the fax attachment. Document will be opened in a new tab. You can view and download it as your wish.
3.Click on the “From” number to open reply window. Now you can select attachment and send as done in above “Send Outbound Fax” section.
Please note that twilio supports only PDF files to be sent . So, ensure that the attachment is PDF.
Fax is a traditional technology. But still it is an essential tool for a variety of organizations – from hospitals to law offices, from pizza shops to the offices of the Federal Investigation Bureau. However, fax was offline and brittle before. Today, it’s online and ready to work for you. Twilfax allows to send and receive faxes between fax capable twilio numbers and fax machines through your android phone.
In this Blog, first we will demonstrate how to set up a twilio fax number then how to send and receive faxes in Twilfax between twilio numbers and fax machines.
You can also learn the whole process by viewing the video Twilfax tutorial .
After signing in to your twilioid account, you can set an existing number in your twilio account as your fax number if it is fax capable or else you can buy and add a new fax number to your account.
If you have fax supported twilio numbers, you can set any one of these numbers as your fax number.
Only fax capable numbers will be listed in fax list. You can select the number which you want and set it as your fax number by clicking “Set Number” button. One thing should be noted, same number cannot be used for both voice and fax. When you set a fax number to receive fax , the number will be unavailable to receive calls. Alternatively you can also set fax number in your twilio account console and link it with the fax url “https://twilioid.com/fax-twiml.php”.
If you do not have a twilio number which is capable of sending and receiving faxes, you can buy and add a new one to your account.
1.You can search numbers by providing country name and an optional area code then clicking the “Search” button. Here, the most important thing is to be noted that you must ensure that the fax capability field is checked instead of the voice.
2.Once the search is finished, available numbers with the given requirements will be shown. Now you can purchase a number from the list which you liked most by clicking the “Buy&Set” button. You can purchase number from your twilio account console and link it with the fax url “https://twilioid.com/fax-twiml.php”.
Once you have completed the setup process, Your current fax number will be shown in the fax number field. You may check it to ensure that your fax number is set.
The Twilfax app for android can download it from the google play store. To download it click download Twilfax from playstore.
If you are using the Twilfax application for the first time, you should login with your twilioid credentials.
1.You will see a screen like the above one. You should have to enter your twilioid login code in the given field to access your twilio account. Then click on “Submit” button.
2.Now you will be directed to a screen like the above one. Here you want to set the default country code. This will be helpful for the future use of the application. Select your country code and click on “Next”.
Once the above two steps are finished, you will be directed to the home page as shown above. Now you have completed the setup process.
Once the setup process has completed, you can now Send your Fax. To send a Fax, you should keep the Fax document which is to be sent as a PDF file in your local storage.
1. Click on the “Send Fax” button in the home page. Then you will be directed to “Send Fax” screen.
2. In the “Send Fax” screen you have to provide a number to which the fax is to be sent. You can optionally select the number from your contacts by clicking the “Contacts” button. After that you should select an attachment (must be a pdf file) from your local storage by clicking on the “Browse” button. After completing this steps click the “Send” button.
Within moments, your fax should be happily on its way to the lucky recipient.
You can also view the inbound faxes in your twilio number and download it to your local storage.
1. Click on the “View Fax” button in the home page. Then you will be directed to “Inbound Fax” screen.
2. In the “Inbound Fax” screen, you can view all your inbound faxes. Click on any item in the list to open the attachment. Then save the file to local storage.
Traditionally, connecting a SIP phone and making calls were cumbersome. It required a dedicated PBX, or expensive cloud telephone. With Twilio Voice supporting SIP registration, it is now easy to utilize the Twilio cloud to power your SIP enabled phone. You can use either SIP hard phones such a Cisco, Yealink and Snom or soft phones such as zoiper, x-lite or sj-phone to connect to Twilio and make calls.
In this Blog, we will demonstrate how to register multiple extensions with Twilio, and to make calls between the extensions and also external calls. We have also provided easy to use scripts that you may use from our server, or modify to meet your specific needs.
Twilio allows to connect SIP-enabled devices or soft phones directly to Twilio and to use the Voice API to handle calls. The following diagram shows how sip endpoints can make calls within and to out side of the network. Sip endpoints can call each other and can make call to out side.Also can receive call external to the system.
We are going to register twilio sip end point in android phone and make inbound and outbound calls with twilio sip end points. We are using Zoiper soft phone, but the same procedure applies for other soft or hard VOIP phones.To register and test Twilio domain endpoints you’ll need a twilio account with an incoming phone number and Zoiper soft phone installed on your phone.
Step 1: Create credential list
Log in to your twilio account go to programmable voice.Select “credential lists” ,create a credential list ,add credentials and save your passwords (we need this later). In this example, your extensions will have a 3 digit number, but with a little programming tweak you may use either 4 digit extensions or even a 1 digit extension.
And you have your credentials.
Step 2: Create twilio sip domain.
Select “Domains” and click the “+” icon.Enter a friendly name and a unique sip uri. We also need to change the request url but we are going to do that later.
Add your credential lists , enable the allow to register end points, add credential lists and save your domain.
Now we all set to register sip endpoints in android phones.Remember the credentials we added in our credential list.Those are the user name and password pair we are going to use here.
Create new account in zoiper , enter user name and password from your credential.Enter your twilio domain name in the Host field.Don’t forget to add region in sip domain name.
Eg : siptwilionethram.sip.us1.twilio.com
Then save and register your twilio end point.You will see a green dot on successful end point registration .Follow the same procedure and register another end point. That extension can be named as 102. You can see the successfully registered endpoints under your sip domain in the twilio console.
Inbound call
First we make a call to our twilio endpoint by configuring the voice url of a twilio number. You may have to purchase a new number. Create a php script CallToSip with following code or you can use the php script we have hosted at “http://nethram.com/sandbox/Twiliosip/CallToSip.php”
for testing.
<?php echo header('content-type: text/xml'); echo '<?xml version="1.0" encoding="UTF-8"?>'; /** Get sip endpoint list **/ $params=$_REQUEST['SipUser']; $toNumberList=explode(",",$params); ?> <Response> <?php for($i=0; $i < sizeof($toNumberList) ;$i++) { $to=$toNumberList[$i]; ?> <Dial timeout="20"> <Sip> <?php echo $to; ?> </Sip> </Dial> <?php } ?> </Response>
To dial a sip endpoint configure the twilio incoming phone number’s voice url with
“http://nethram.com/sandbox/Twiliosip/CallToSip.php?SipUser=100@siptwilionethram.sip.us1.twilio.com”.
Or with script hosted in your server. Replace sip endpoint with yours.
Dial twilio number from any of your voice network and call will be forwarded to your twilio endpoint registered in android phone.
You can also call to multiple sip phones(sip endpoints) by adding coma separated sip end points to voice url as “http://nethram.com/sandbox/callbackweb/CallToSip.php?SipUser=100@siptwilionethram.sip.us1.twilio.com,101@siptwilionethram.sip.us1.twilio.com”.
Out bound call
Next we are going to make call from our twilio end point.Create a new file calltwiliosip.php and copy the following code or you can use script hosted in our sever
“https://www.nethram.com/sandbox/callbackweb/calltwiliosip.php”.
<?php echo header('content-type: text/xml'); echo '<?xml version="1.0" encoding="UTF-8"?>'; $to=$_REQUEST['To']; $callerId=$_REQUEST["callerId"]; /** Extracting user name **/ $pos1 = strpos($to,":"); $pos2 = strpos($to,"@"); $tosip=substr($to,$pos1+1,$pos2-$pos1-1); if(strlen($tosip) == 3) { /**Extracting sip endpoint**/ $pos2 = strpos($to,":",strpos($to,":")+1); $tosip=substr($to,$pos1+1,$pos2-$pos1-1); ?> <Response> <Dial> <Sip> <?php echo $tosip; ?> </Sip> </Dial> </Response> <?php } else { if(substr($tosip,0,2)=="00") $tosip=substr($tosip,2,strlen($tosip)-1); if(substr($tosip,0,3)=="011") $tosip=substr($tosip,3,strlen($tosip)-1); ?> <Response> <Dial callerId="<?php echo $callerId; ?>" > <?php echo $tosip; ?> </Dial> </Response> <?php } ?>
Configure your sip domain’s voice url with
“https://www.nethram.com/sandbox/callbackweb/calltwiliosip.php?callerId=+12246048844” or the script hosted in your server , replace callerId with any of your twilio incoming phone number, or a verified Twilo number.
If the user dials a 3 digit number then the script assumes that it will be a sip extension and script will forward the call to the corresponding sip extension. In all other cases, the script assumes that it is a phone number and call will be forwarded to the corresponding number. International numbers should have a 00 or 011 prefix, and the this prefix will be substituted with “+”.
To test first case dial 100 (registered end point username) from zoiper soft phone.Dial a 10 digit phone number to test the second case.If you dial an international phone number be sure that global permissions for the country is enabled in your Twilio account.
Now your lambda functions are ready and functioning. The next step is to enable them to access from the Amazon API Gateway and pass the necessary parameter to each Lambda function.
In the same page where you upload your lambda function click the Get method under the API endpoints tab. Then it directs you to a new page where you can configure your API. A new page will appear as below. Click on your API (for example – CreateAccount ).
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "CreateAccount",
"type": "object",
"properties": {
"name": { "type": "string" },
“password”: {“type”:”string”}
}
}
Note: Here in this example we are giving two parameters under the properties key, because this model is using for CreateAccountfunction’s API configuration. In order to do the same for UpdateStatus function API we needed to include one more parameter inside the properties. The third parameter is the status parameter.
{
"name": "$input.params(‘name)",
“password”: “$input.params(“password”)”
}
Now the parameter query string parameter is passed to the here and a new json formatted body is created.
Select Integration Response section to create an output mapping template. It is similar to the template that we did in Integration Request to create input mapping template. Select the Content-Type as application/json. The HTML page is stored inside a variable. That same string we needed to capture from the lambda function. Follow the code given below
#set($inputRoot = $input.path('$'))
$inputRoot.respon
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "OutputModel",
"type": "object",
"properties": {
"resp":{"type":"string"}
}
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "updateStatus",
"type": "object",
"properties": {
"name": { "type": "string" },
"password":{"type":"string"},
"status":{"type":"string"}
}
}
Add the following template datas in the Integration Request section.
{
"name": "$input.params('name')",
"password":"$input.params('password')",
"status" : "$input.params('status')"
}
The getAllStatus API configuration is same as that of CreateAccount function.
Now the models and mapping templates are ready to use. Next step is deploying the API. There is a button called Deploy APIclick on it. Select a deployment stage and deploy the API . Then you can configure Cache settings, CloudWatch settings and Throttling settings. Invoke url will be displayed on the top of the screen.
Sign in to the AWS console and select the Lambda . Then follow the instructions to create a lambda function. This session shows the steps to create first lambda function- CreateAccount for our application . Follow same steps to create two more functions, that are UpdateStatus andgetAllStatus.
This role template has a predefined access policy that grants sufficient permissions for AWS actions that your Lambda function needs.If you need more access permissions for your needs you can create a new IAM role and assign a name (for example, lambda_dynamo ) as the execution role. Here we use the predefined template Basic with DynamoDB. Press Allow button then click Next.
Note: Make sure you have selected the Open from the Security list. Because we create this function for invoke it from web browsers without authentication process.
You will get a following screen make sure your configurations and click Create function .
There are various options to deploy lambda function to aws. First one , we can use the editor available in Lambda console. and the second option is uploading a lambda package from our local machine to aws as a zip package. Final option is using lambda package stored in the amazon S3. In this scenario , we use the second method , that is directly uploading our lambda package from local machine to AWS lambda. It is because we are using MySQL database in RDS for this application. For that we need to include additional MySQL module to our package. we can’t do this in the editor available in Lambda console.
A:Create a Lambda function deployment package
sudo npm install mysql
sudo npm install fs
B: Create lambda function and html contents.
Inside each folder create the node.js file and other required files for the execution of the functions such as files containing HTML contents
CreateAccount
UpdateStatus
GetAllStatus.
C:Uploading the Lambda package
For example, after uploading the CreateAccount zip package we test the function by giving the parameters such as name and password. The JSON text event body is like this.
{
"name":"janet",
"password":"janet1234"
}
{
"name":"janet",
"password":"janet1234",
“status”: “This is my test status”
}
make sure that your dynamoDB table has new entry after the test.
For getAllStatus function. use the test event shown in the first example.
This application gives a complete overview of how to use AWS resource (such as DynamoDB and RDS) with Lambda and how to return an HTML page as a response to every incoming request. Here we are using Amazon RDS for storing user’s account information and Amazon DynamoDB for storing user’s status information. The web app is stored in Amazon S3. It is important to note that EC2 is not used. Hence there is no reserved infrastructure.
Note: There is no need to use both RDS and DynamoDB simultaneously. This example is using both to show that lambda can interface with both.
We will create 3 lambda functions and invoke these functions from separate API endpoints. The Lambda functions are
You are just few steps away from creating your Lambda application.
a. Create and configure RDS MySQL database instance
mysql -h RDSEndPointAddress -P 3306 -u username -p databasename < PathTORDSdatabaseSchema.sql
For example
mysql -h lambdaInstance.cukvxrgt8kqg.us-east-1.rds.amazonaws.com -P 3306 -u user -p lamdaApp < RDSdatabaseSchema.sql
Give password.It will configure your database.
b. Create DynamoDB Table.
Building scalable systems is often unmanageable even with cloud computing. Normally we use Amazon AWS with EC2 , load balancer and autoscaling. This approach is inconvenient and sudden traffic spikes cannot be handled with autoscaling. Additionally some infrastructure should be always kept in reserve.
Aws Lambda can be used to solve these hassles of AWS load balancing. AWS Lambda is quite promising, easy to use and does not have the above limitations. The trick of using AWS Lambda with Amazon API gateway can help you build and scale web-applications with no infrastructure reservations.
AWS Lambda is a platform to make completely scalable applications with less effort and without the hassles of virtual machines. You need to upload your application code as “Lambda” functions to AWS. AWS Lambda runs your code on high-availability compute infrastructure and performs all the infrastructure functions, such as administration of the compute resources, capacity provisioning and automatic scaling. Those Lambda functions can be triggered by Amazon API endpoint, thereby exposing to the web. All you need to do is upload your code in one of the languages that AWS Lambda supports (currently Node.js or Java).
This document includes stepwise procedure for Building a completely scalable and reliable cloud based application using AWS Lambda.In this part we will see working example of scalabe lambda application.This involves creating a web Interface for app, construct AWS Lambda function, configure APIs in Amazon API Gateway and invoke the application from web browser.
This demo application is a poor man’s facebook. The source code is available at github (https://github.com/Nethram/LambdaDemoApplication) It has 3 functionalities. Those are
Use this link to test this application. It opens the following interface.
Source Code :https://github.com/Nethram/LambdaDemoApplication.
Howdy is a voice application that encourages citizens of the world to talk with each other. A person anywhere on the globe can tap on his phone, connect with a random stranger somewhere else in the globe. They can speak with each other in order to jointly solve a puzzle, one that can only be cracked by collaborative discussion. It’s kind of like the world’s biggest game of pub trivia, or a global ice breaker. Howdy games are based on general knowledge, science, history and maths. Howdy is capable of entertaining and at the same time it can be a tool for improving and exchanging knowledge, make friends, have fun, unite the world and at the same time improve your communication skills, general awareness and knowledge base.
Howdy is a free app and is available at Google Play store. It is also available through web browser. The app is easy to use, once installed the user connects to the Howdy server. Hit the “Talk” button and they’re connected to a random person and have three minutes to make a connection and say whatever they’d like.
By hitting the “Talk ‘n’ Solve” button, they’re connected with a random person and the pair have five minutes to solve the puzzle which can only be done with verbal co-operation and communication.
Users also have an option of leaving a voice message for the rest of the Howdy users. Another Howdy user can retrieve this message by pressing the “Fetch” button, one message will be retrieved – like an electronic note in a bottle.
Howdy! brings back the excitement of long distance communication. Once there was a time when talking to someone in another country was a novelty. Long distance telephone calls were expensive, but the excitement of talking to someone on the other side of the globe was thrilling. “What’s the weather like there?” “What are you eating for lunch?” Just simple questions about our shared daily routines helps to remind us that we’re all one human family.
Security features for Howdy include the ability to block a person and an option to report abuse.
Howdy is built as a platform for building massively scalable web and app based voice applications. The platform can be re-used to build large voice applications such as google talk.
Howdy is available for Android at Google Play store and can be downloaded from https://play.google.com/store/apps/details?id=com.nethram.howdy
Howdy is also available through web browser at http://howdytheapp.com
PhonePay is a web based software tool which helps you to collect payments from your customers via phone calls. It provides an interactive voice response system with assigned Twilio phone number and payment is made through stripe.
Consider Mr. John Doe and his Pizza Hut where he is using PhonePay as a payment option. His customers give their orders through phone or some other means. They are advised to call his PhonePay number and pay the billed amount.
John Doe is able to verify their payments in PhonePay’s admin panel. If customer cancels order or if he wish to give some discount , he can refund the desired amount to the customer from admin panel. Also if the customer expands his order, shopkeeper is able to charge overage at any time by a single click.
Features
Prerequisite
A web server :
PhonePay run on PHP-MySql enabled web server.
Stripe Account:
You should have a working Stripe account to collect your payments.You can create a free account by registering at www.stripe.com.
Twilio Phone number:
Set up a working phone number at www.twilio.com. Your customers have to call this number while attempting to pay for your service
or product.
Get Started
It is easy to get started with phone pay. Get a copy of source file from www.github.com. Extract all files to your web server and open it in your favorite web browser. PhonePay’s installer GUI will help you in completing installation. During installation you will be asked to enter database credentials and Stripe keys.
After installation you have to enable your Twilio number by changing its Request URL. This is done from the the Twilio account at www.twilio.com. Request URL for PhonePay installed at www.myphonepay.com will be http://www.myphonepay.com/twiml.php.
Now you have a working PhonePay service. Make your first call to your PhonePay number, you will be answered by PhonePay’s IVR.
How it works
Users calling to your PhonePay’s number will be answered by its interactive voice response system (IVR) .The user will be lead to pay through Stripe. User will be prompted to enter credit card details by IVR. PhonePay does not store any credit card details on server. All call logs and payment details will be available in Admin Panel. Admin can manage orders and also if needed, refund the amount to the payer. If any customer updates his order, admin is able to charge overage by a single click in admin panel.
Phone Pay can be configured in four different modes called system behavior. System behavior is switchable based on your needs at any time from admin panel.The four system behaviors are as follows.
Set a system behavior best suited to your business and start selling with PhonePay. If you have any question or if need any support please write to us at support@nethram.com. Also you can explore and write at PhonePay’s support form for any questions at http://forum.nethram.com.
Screen shorts: