Perl VoIP developers 101
Part 2: Perl example on recording VoIP calls, call routing
The Ozeki Phone System gives you the opportunity to use its special features. If you are a developer and the previous guide was not enough, you can find more information how to route, log or record calls.
- Reference manual: HTTP API Online Manual
Introduction
On the previous page the first part of Perl VoIP developers 101 can be read. That guide presented the prerequisites of doing basic tasks, such as SMS sending/receiving or making/receiving a call using your own Perl application. This article focuses on far more advanced features, like call logging or call routing.
Part 1: Perl example on sending SMS, making VoIP calls
Getting started
First of all, you need to install a web server and Perl on your PC. The easiest way to do this, is installing Wamp package which includes Apache web server. You can download it from here.
1. Log calls
To log calls, you must change the settings at PBX, Productivity menu, http API menu item where you need to give a URL and select which script is executed if the call status changes. In this case it is a Perl script. So write the URL of the script into the ‘Call changed URL’ field and save it.
After a call state changed, the PBX will send an HTTP Post to the given URL with the data of the call. In the script you can read the posted call data:
use CGI qw(:cgi-lib :standard); &ReadParse(%in); |
Then you can log the data on a simple file:
open(my $fh, '>>', 'callChangedReport.txt'); print $fh "NotificationName:$in{'NotificationName'}, CallState:$in{'CallState'}, CallId:$in{'CallId'}, Caller:$in{'Caller'}, CallerId:$in{'CallerId'}, Callee:$in{'Callee'}, CallDate:'$thisYear-$month-$day $hour:$min:$sec'";
2. Record calls
You are also able to record the calls with your PBX. It is required to use your Call changed URL. So, the entered script can start the recording with an instruction. Attribute of finshedUrl is the URL which gets the URL address of record. You can choose the format of recording (mp3 or wav) in format attribute.
<Response> <Record finishedUrl=" http://yoursite.com/RequestRecord.pl" format="mp3"/> </Response> |
At the end of the call, PBX sends the URL of the record to the script which was given in finishedUrl. First, script will read the data.
use CGI qw(:cgi-lib :standard); &ReadParse(%in); |
Then you can log the call data onto a file or a database. The following parameters are posted:
Success, Duration, RecordURL, Caller, Callee, CallId, NotificationName
For more information about the parameters, please visit the following link: http://www.ozekiphone.com/http-notifications
3. Call routing
Besides Dial Plan, it is possible to give a Perl method, so you can decide which extension answers the call when forwarding your calls. If you did not forward the call, it will be handle by the rules of Dial Plan. You can enter into the Route interception URL field the path of your method (e.g. http://yoursite.com/RouteCalls/RouteCall) in the Productivity menu's, HTTP API submenu. Perl script reads the call data.
use CGI qw(:cgi-lib :standard); &ReadParse(%in); |
Then, there is a call for HTTP API extension and it is forwarded to extension 1100 and waits just one ring.
print "<?xml version='1.0' encoding='UTF-8'?> <Response> <Route RingTime=”1” Destination=”1100"/> </Response>"; |
If the previous call was busy, the call can be forwarded to extension 9998:
if ($in{"LastCallState "} == "Busy"}) { print "<?xml version='1.0' encoding='UTF-8'?> <Response> <Route Destination=’9998’/> </Response>"; } |
RingTime attribute is optional, it is 90 by default.
If you do not want to forward the call, print an empty string of the script response, so the rules of dial plan work.
You can read more about Route command here.
Part 1: Perl example on sending SMS, making VoIP calls
This guide taught you how to use the Ozeki Phone System to a more advanced level. Now, you are able to log, route and record calls.If you have any questions or need assistance, please contact us at info@ozekiphone.com
More information
- Part2: Perl example on recording VoIP calls, call routing
- Part1: Python example on sending SMS, making VoIP calls