Our strategy is to allow people work remotely and concentrate more on results than spending a fix number of hours in the office. The goal of this project was to allow the sales people which work remotely to call clients over the internet using the phone lines from the headquarters. Other goals:

  • integration with our sales platform (www.solis.ro)

  • can call using the data from the CRM

  • reporting using the integrated tool

  • allows the sales persons to access their own calls for analysis

  • does not require special hardware or configuration for the sales persons

  • runs on Linux on the server side and on windows and Linux on the client side

  • has a low cost

Start idea

The idea was to use Asterisk PBX a software solution which will power the hole setup. I had some basic experience with the PBX and it’s manager API from an older project.

Connection to existing phone lines

In order to connect to the existing phone lines you require some kind of hardware integration to your Asterisk software. You need in fact to connect the phone lines to FXO ports which are connected to Asterisk. Normally the recommended setup is to use Zaptel or other compatible PCI cards but in Romania they are very hard to find and expensive so I decided to find a device with FXO ports which speaks SIP. I found some reasonable priced (~150 EUR) Wellgate device with several FXO ports. By default the device has a H232 stack but you can easily change the firmware using a serial cable and a tFTP server. The SIP firmware can be downloaded from the producer site. After some straightforward enough configuration you have a SIP device connected to your phone lines.

Connecting the SIP device to Asterisk

In order to connect the SIP device to Asterisk you need to modify the sip.conf configuration file in order to add the SIP peers. I for each FXO, FXS line.

[900]<br></br>type=friend<br></br>username=900@192.168.2.200<br></br>callerid="900"<br></br>secret=xxxxx<br></br>host=dynamic<br></br>dtmfmode=inband<br></br>deny=0.0.0.0/0.0.0.0<br></br>permit=192.168.2.201/255.255.255.255<br></br>

Asterisk clients (softphones)

On the client side I choose to use the IAX protocol due to it’s flexibility to pass through NAT and other networking problems I had with SIP. Initially I lost a lot of time trying to use SIP softphones such as x-lite but in the end I found a mozilla plugin called MozPhone which is very simple to install and use. It also has the advantage that it registers the tel: protocol.

SOLIS knows to generate tel: links using the CRM phone data so the sales people can just click the phone link in their Firefox browser in order to dial the client. The only hardware required on the client side was a good headset with microphone (~ 10 EUR each).

Here is the configuration for a IAX client in iax.conf

[salesOper1]<br></br>type=friend<br></br>host=dynamic<br></br>username=salesOper1<br></br>secret=xxxxxxxxx<br></br>context=default<br></br>disallow=all<br></br>allow=gsm<br></br>callerid="John.Doe"

The dialplan

Configuring the dialplan requires to know what the desired behavior is. In my case:

  • all calls from the outside to the FXO lines had to be directed to an FXS port for a local operator to answer
  • all calls from IAX clients with numbers from the CRM had to be forwarded to one of the SIP FXO lines
  • all other calls had to be rejected

All this is done in extensions.conf. There are a lot of examples on http://www.voip-info.org from which I inspired myself. The only tricky part was to pass the EXTEN to the SIP line in a way usable. This is where the dtmfmode=inband from the SIP config is required. On the extensions.conf the last line passes the data to the SIP:

exten => _0[237]XXXXXXXX,7,Dial(SIP/900,10,tD(w${EXTEN}))

CDR

In order to have call statistics you need to enable CDR. In my case I enabled postgresql CDR using the cdr_pgsql.conf file. This has allowed later integration with the sales reporting tool

Cleaning unused modules

One of the tasks which you are most tempted to forget is cleaning up your modules.conf file. I think however it is necessary to disable as much modules as possible.

Advanced stuff: recordings, more integration with SOLIS CRM

Recording conversations is only a matter of 2 lines of configuration in the extensions.conf

exten => _0[237]XXXXXXXX,5,Set(CALLFILENAME=${NITCID}-${EXTEN}-${SOLISCNAME}-${TIMESTAMP})<br></br>exten => _0[237]XXXXXXXX,6,Monitor(wav,${CALLFILENAME},m) 

The more complicated part was to obtain the NITCID – operator name and SOLISCNAME – client name from the CRM. For the first variable, since 1.2, Asterisk offers the CALLERID function which is of help:

exten => _0[237]XXXXXXXX,3,Set(NITCID=${CALLERID(name)})

but in order to obtain the client name from the CRM an AGI script had to be written:

#!/usr/bin/perl<br></br># load module<br></br>use Asterisk::AGI;<br></br>use DBI;<br></br><br></br>#param<br></br>my $tel = $ARGV[0];<br></br># connect<br></br>my $dbh = DBI->connect("DBI:Pg:dbname=xxxxxxxx;host=localhost", "xxxxxx", "xxxxxxxx", {'RaiseError' => 1<br></br>});<br></br>my $sth = $dbh->prepare("select .........;")<br></br>;<br></br>$sth->execute();<br></br>my $cname = "";<br></br>my $cid = "";<br></br>while(my $ref = $sth->fetchrow_hashref()) {<br></br>    $cname .= "$ref->{'nume'}";<br></br>    $cid = "$ref->{'id'}";<br></br>}<br></br>$cname =~ s/[^a-z0-9.]/_/gi;<br></br><br></br>$dbh->disconnect();<br></br><br></br>$AGI = new Asterisk::AGI;<br></br>my %input = $AGI->ReadParse();<br></br>$AGI->set_variable('SOLISCNAME', $cname);<br></br>$AGI->set_variable('SOLISCID', $cid);<br></br>exit;<br></br>

This script has to be put in the /var/lib/asterisk/agi-bin directory and must be given executable permissions. In fact I lost 10 mins with the fact that the script was not executable by the asterisk user and there was no error reported in the log.

Now the variables SOLISCNAME and SOLISCID have been set in the channel space and can be used to generate the file name and to store referencing data in the CDR table for further linking and reporting.

In order to cope with the size of the recordings I encode the wav files to speex using speexenc and delete them weekly.

Final costs estimates

  • SIP FXO device: 150 EUR
  • headsets with microphone 5*10 = 50 EUR
  • Linux server (old Duron 1G, 512MB ram) build from old components ~ 200 EUR
  • asterisk expertise (I spent around 30h on this on various moments) priceless and free
  • TOTAL cash: 400 EUR

Comments:

Prasad -

Dear Len, I am trying to develop a similar application through which the sales people can make calls. I have Asterisk installed and configured for IAX. I have Mozphone plugin installed and configured with Asterisk server information. I wrote a simple html file with code “39791”. When I load the html file and click on 39791 link, the mozphone is opened but nothing happens. The call is not placed. I am see the following errors in firebug. [Exception… “‘Method not implemented’ when calling method: [nsIChannel::suspend]” nsresult: “0x80004001 (NS_ERROR_NOT_IMPLEMENTED)” location: "" data: no] [Break on this error] undefined d.getElementById(“bcall”) is null Could you please tell me what I am missing here. Thanks a ton, Prasad


len -

Hello, I think there is a problem with your URL, it should be something like: 021 211234 Len