Click-to-Call with your Asterisk@Home Box
Click-to-Call seems like it would be a complicated task to setup; enabling a website visitor to click a button to allow them to submit their phone number, and receive a call from someone a few seconds later, with no long distance charges for the visitor.
If you have an AAH or Asterisk box, it really is not that difficult to add such a feature to your website. A very simple PHP page hosted either on your AAH box, or another PHP-capable web server (that has TCP connectivity to your AAH/Asterisk box) is all you need. Last night I developed such a script, and though it is rather simple, it's effective. I plan on doing more with it later, but thought I'd share it will all of you so that you can begin playing with it, or customizing it yourself. This script was written for AAH, so it probably will not work with a regular Asterisk box without some modifications, or even a heavily customized AAH box. However, it's very straight-forward, and should not be hard to debug if you have problems with it.
To the expert PHP'ers out there, this was my first attempt at doing anything with PHP (I'm an ASP guy), so have pity on me!:)
Ok, here it goes.
I'm going to be explaining how to set this script up on an AAH box, but as I said before, it should work on any PHP server that can communicate with your AAH/Asterisk box. Also, I have only tested this on AAH 2.4, so I don't make any guarantees that it works on anything else. In fact, I don't make any guarantees that it works on any AAH 2.4 box besides my own, though it should. :) While I'm at it, I may as well also mention that if you decide to use this script, you do so at your own risk.
Step 1:
Login to your AAH box and enter these commands:
cd /tmp
wget http://downloads.voipjots.com/scripts/click-to-call.zip
unzip click-to-call.zip
mv click-to-call.php /var/www/html/click-to-call.php
rm click-to-call.zip
Step 2:
Now we have to slightly edit the script to get it to work for you.
cd /var/www/html
nano -w click-to-call.php
For a typical AAH box, you should only need to edit one line in the script. Change the line:
$strChannel = "IAX2/250";
to reflect one of your extensions. In my case, I am using my Idefisk IAX2 softphone that has an extension number of 250. For instance, if you have a SIP soft/hard phone that has an extension number of 1234, you would change this line to:
$strChannel = "SIP/1234";
Ok, at this point, we should have everything properly configure on our AAH box. Now we can try it!
Step 3:
In a web browser, go to http://my-aah-ip-address/click-to-call.php
You should see this:

While near the soft/hard phone belonging to the extension you specified above, enter a valid 11 digit phone number, and click on the Call Us! button.
The soft/hard phone should begin ringing, showing "Web Call
The click-to-call web page should now be this:

This script is very simple, and probably not best hosted on your aah box, but on another web server that hosts the site you would want to add click-to-call functionality to. However, I hope that this provides a good demonstration as to exactly how simple it is to implement click-to-call with AAH, and leave it to you and your creativity on exactly how you wish to offer this feature. The sky's the limit, really.
I hope this has been helpful to someone. If you have any ideas on how to improve the script, please let me know by leaving your comments. If you make significant improvements to the script, I would appreciate it if you shared them with all of us.
Enjoy!
Olin
26 Comments:
WOW, I did it on my box and it worked first try. Very cool use of this technology.
You really made my day. I did this on AAH version 2.5 it really works. I wish I could get any of the enhancements that you may do. I can’t do any programming but it’s real fun using what you guys do. I have been looking for something like this for some time now, but companies charge big money to offer a call back service like this for a website. May be you can add the option to have a varying number of digits entered in the “call us” box so it can be used by international friends as well.
GOOD JOB, AND THANKS VERY MUCH FOR SHARING.
Thanks Terrence!
I'll remove the limitation of only accepting US calls, and will hopefully include another option that has been mentioned to me; allowing an extension number to be added for calls to a location behind a PBX. I'm also going to figure out how to have the AAH box give the "please wait while I connect you call" greeting when the call is answered on the channel, before it dials the external number. Hopefully I'll have all of this done and working in the next week or so. If you think of anything else you'd like to see with it, please let me know!
Olin
Seeing that you ask. A couple of things that comes to mine are: 1) “Center justify” the text messages on the web user side. 2) Add option to use another trunk line to call out to a cell phone say instead of an extension, and 3) If there is no answer on the asterisk side of the call, have asterisk call the remote persons number any way and play a message like “Sorry there isn’t a live person available to call you at this time, please try again later”, so that they will know it worked and will try it again later.
Terrence
Terrence,
Good suggestions. Center justification is no problem. The option to call a cell phone instead of an extension would be possible only if you had at least two trunks in your asterisk box, as it would take a trunk to call the cellphone, and a trunk to call the entered number. It could be done though. Your suggestion of calling the person regardless of whether or not the call is picked up is a good suggestion. I'll try to work these into the next script.
Olin
I don't know the license status for this code, but I made some modifications in order to having it work with my * config. I translated the text to spanish, restricted the calls to 10 digits (my dialplan provides for the area codes that I allow to call out to in 10 digit format) and finally I set the extension to be my cell phone (just entered IAX2/voxee/MY_PHONE_NUMBER). It works great! Thanks for the code. Please let me know if I can help you with anything at all with this code. rd_cortes (a_t) walla (do_t) com.
Rafael Cortes,
Are you working with AAH or with Asterisk cause it would bevenry nice to use this click-to-call script on Asterisk.
David
i see php code and fown parameter WaitTime at line fputs($oSocket, "WaitTime: $strWaitTime\r\n"); but i can't found this parameter in manager.c - only Timeout.
Hi,
I'm working on something similiar and came across that few seconds pause too between the pickup of the local phone and * dialing the remote one.
Do you have some info, some pointers why this is happening?
Ciao,
dev
Hi. This is nice and simple, But I would not open my manager port to the internet though. Also no logfile seems to be created to track (mis)use. Personaly I use the call files and a "client server" model. where the form is submited on any web page and the relevent data is posted back to *, then manipulated and passed as a call file, Using its own context allowing only specific calls at specified times.
Ian
Thanks Olin, I had something similar that I am using in our commercial deployment, but I must say that yours is much cleaner. I am putting a link to this post in my blog.Phil Peterman
Hi.
Had a chance to look at the script, I do think doing it as a server/client will make it more secure though, in this method the only data passed to the server is the phone number and users name and call subject, This is then used by * to compile the call information, and the CLI that will presented to the agent. The logging and email notification contains the requesters IP address and proxy information.
If you want to see what I have feel free to email me.
Well Im amazed with these scripts that are aprearing. who in their right mind would implement a app that can be called from any where with just "http://AAH.Box.IP/call.php?from=1111111111&to= 2222222222" I think the script kiddies will be scanning the manager port more often.
Come on get serious everyone, None of these mention any of the measures that need to be put in place to secure the script and the server.
Ian,
I would be interested in seeing what you've done. I didn't catch your email address anywhere though. Would you email me at ohamilton(a t)voipjots[d0t].com?
Thanks,
Olin
Anonymous said...
Well Im amazed with these scripts that are aprearing. who in their right mind would implement a app that can be called from any where with just "http://AAH.Box.IP/call.php?from=1111111111&to= 2222222222" I think the script kiddies will be scanning the manager port more often.
Come on get serious everyone, None of these mention any of the measures that need to be put in place to secure the script and the server.
I believe we all know the security issues here, but also know that they can be addressed. This script was an example script only to aid with further development of a more robust/secure application that a developer could tailor to their specific needs. If you have suggestions on how to make such an application more secure, please submit as comments on my next post: Asterisk@ Home Click-To-Call Application Ideas
Olin
It would be nice if you logged into the script on the website site of things so when people are not there the asterisk machine does not make the phone calls. Very much like a support agent system.
Hello there, Nice script! just one question:
I tried to dial a local extension within the LAN but did'nt work, but when I try a external phone works great! where in the script can I modify it to make it work with 4 numbers extensions?
thanks.
I tried to dial a local extension within the LAN but did'nt work, but when I try a external phone works great! where in the script can I modify it to make it work with 4 numbers extensions?
You would need to prefix the extension you are wanting to call with whatever protocol it is using. e.g SIP/xxxx, IAX2/xxxx, ZAP/xxxx. Let me know if that works.
Olin
Hi,
Has anyone worked out how to call multiple extensions or ring groups - so that the first extension who picks up the call gets connected.
Regards
Dave
Hi Olin,
I tried this on AAH 2.7 and it did not work. When I enter the number on the webpage, my softphone rings showing web call and when I answer the call, nothing happens, its does not ring the entered number. Can u pls help me with this issue?
Normally from my softphone to dial out , I dial 9 first, so do I have to change anything in the script ?
Please let me know.
Hi,
Just to see if it works, change the 11 in this line in the script to 12.
if ($length == 11 && is_numeric($strExten))
Then, in the webpage text box, enter in a number to call in this format: 91XXXXXXXXXX.
If this works, then you have a few options, but the simplest would be to just have the script concatenate a 9 in front of the $strExten variable.
Hope this helps.
Regarding my previous comment, there is another change you will need to make as well.
input type="text" size="20" maxlength="11" name="txtphonenumber"
Change the 11 in the above line to 12 as well. This line is on line 96 of my script.
wow cool script.. I would like to use this script but I need it to call a Ring Group and I would also like it where they enter their phone number and then choose from a drop down list what department they wanna talk too such as Sales, Billing, Support, etc.
I was wondering how I can modify the so it call stwo regular phone numbers. I have two trunks setup already thank you.
Awesome. Works on the first try. Wonder if I can set it up to auto call back once I pick up the reciever? Thanks for the code!
I have modified the script a little bit...
actually I have made 3 more versions of it,
one calls the webpage user first and connects them to the IVR using the time conditions (Needs a custom-context in extensions.conf),
the second one lets you write your number, calls you, asks for your passcode, and gives you DISA (this also requires a custom-context, and for security I placed it in the admin folder so it asks for user and password before accesing it,
the last one lets you write the number at which you want to be called, and the number you wish to call, this one needs two custom-contexts (for security) and is also in the admin folder so it asks for user and password before you can use it.
If anyone needs the scripts, email me at rd_cortes (at) walla (dot) com
Post a Comment
<< Home