Announcing AstJAX Firefox Dialer Script
YapTele.com is proud to bring you a cool little greasemonkey script which allows you to click and dial phone numbers, automatically recognised from any webpage and originate the call to your IP phone via Asterisk.
The advantage of this script, is that it makes use of the greasemonkey ajax callbacks, which allows you to click and dial a number from a hyperlink, without navigating away from the current webpage.
You can download AstJax here, click read more for Installation instructions.
Installation Instructions
- Download AstJax
- Install greasemonkey
- Edit clickToCall.php (self explanatory)
- Deploy clickToCall.php to your webserver
(does not have to be the server Asterisk is on, as long as the webserver's IP has manager access (see manager.conf) - Edit astjax2.user.js
- Define the url where you have deployed clickToCall.php
- For US/Canada number recognition, uncomment the US numberRegex constant, and comment or delete the UK one
- Navigate firefox to the location of astjax2.user.js
eg "file:///home/rick/astjax2.user.js" or "c:\astjax2.user.js" etc. to install the greasemonkey script
Currently there are number parsing RegEx's for UK and US/Canada. Although this is very simple to modify for another country. You can even probably find an existing regex for numbers in your county's format at RegexLib. If you write a regex for your country's phone number format, be sure to tell us by leaving a comment so that we can add it to the script for others.
The script is based on the UPS linkify concept by by Logan Ingalls, and clickToCall.php by VoipJots.com - Props!. It also requires a manager connection to Asterisk.
Dial away! Feel free to leave any comments.



Here's the line for italian fixed number (not cell phone)
const trackRegex = /0([0-9][0-9]*\-?\ ?\/?[0-9][0-9][0-9][0-9]*)/ig;
Awesome Script! After playing around with this for a little while I have made some modifications to have the regex hit on more number formats (US only!)
This should hit on the following formats:
1XXXXXXXXXX
1-XXX-XXX-XXXX
(XXX)-XXX-XXXX
XXX/XXX-XXXX
XXX.XXX.XXXX
1XXX.XXX.XXXX
XXX XXX XXXX
And almost all combinations of the above
const numberRegex = /([1]?)((\(\d{3}\)?)|(\d{3}))([\s-./]?)(\d{3})([\s-./]?)(\d{4})/ig;
This is great but the regexp was getting a bit too specific for me. Telephone numbers are a pain to match:
const numberRegex = /(\+\d{1,3}[\-\.\s\d\(\)]{9,17}|\b0\d{2,4}[\-\.\s\d\(\)]{7,15})/ig;
We mostly want to dial from a datbase where numbers are either written in international format, or UK format.
This matches:
1. Anything beginning +, followed by 1-3 digits, then some more digits or [- . space ( ) ] from 9 to 17 characters. (International IDDD format numbers like: +44 20 7043 7996)
2. Anything beginning "0" followed by 2-4 digits. (i.e. a UK number like 020 xxxxxxxx or 01733 xxxxxx)
Any other wacky country specific number formats at the moment are not picked up, but you could just modify this regexp or add your own matches into the list.
Hi
This is a nice script. to aid it being used in "larger" deployments. I have changed the script and PHP so that the calling channel is now stored in the .js script and passed to the PHP. This means that only the .js needs to be altered for each user which is simple as they just install their own one into greasemonkey.
Changes are in the .js script
Below
//Server address and clicktocall file name
const scriptURL = 'http://SERVERADDRESS/clickToCall.php';
The following line is added.
//Users Extension channel. Is now and passed to the C2C script
const scriptEXTEN = 'SIP/2206';
and
url: scriptURL + '?EXTEN=' + scriptEXTEN + '&number=' + String(numb).replace(/[\-\s\/\(\)\.]/g, "")
});
in place of the original url line
in the PHP
the line
$strChannel = "SIP/2206"; removed as now passed from the .js file
is replaced by
$strChannel .= $_GET['EXTEN'];
then all you need is a astjaxXXXX.user.js for each extension.
also in the PHP a sleep(2) does need to be added.
Ian
try this for all United States numbers:
const numberRegex = /((\(\d{3}\)?)|(\d{3}))([\s-./]?)(\d{3})([\s-./]?)(\d{4})/ig;
Also - do not forge to follow the post below with the sleep statement
Hi ,
Am new to Voip and give some detailed information for install and develop this.do not know how to install greasemonkey .
Thnks in advance
The script logs in and out (seen in *CLI) but doesn't make the call. No matter what I do, I can't get the script to dial. If I do everything manually, in * Manager, it works, but when I run the script, I just get
== Manager 'admin' logged on from 127.0.0.1
== Manager 'admin' logged off from 127.0.0.1
No call info.
Any ideas? Please help.. this is a great script, If I could get it to work.
Thanks in advance.
Marcus
I got it.
I needed to add a Sleep(2); before the fclose($oSocket);
That fixed it. Finally.
Marcus
Thanks, I have updated the zip package to reflect this change.
Hi guys!
Could you make a regex pattern for me for this number +632xxxxxxx and +63xxxxxxxxxx where x represents any number from 0 to 9.
Also, how can i used it after following the installation instructions above?
Thanks in advance,
jess
very good! working just fine! here in Brazil!
thanks nice work!
Here's a better regex for Brazilian users.
It will match 8 digit numbers, with or without "dash" preceded or not with prefix using or not using () eg. (031)
const numberRegex = /\b((0\d{2}|\d{2})(\)|) (\d{4}(\-\d{4}(?= )|\d{4}(?= ))))| (\d{4}(\-\d{4}|\d{4}(?= )))\b/ig
enjoy,
Caio Zanolla
Really Great!!! Works for me in France I have just change the pattern
and that's ok reallygood job!
Cheers,
Alex
Worked a charm for me in UK. Thanks!
It works ok.. but i always have to set an account SIP in clickToCall.php If i want to the script get a channel of the user who is using the web site. How can i send the channel to the scrpit dinamically..?
Thanks from Peru.
Can someone paste a German regex?
Great Work!!
Thx
Not working here, works on some websites but most it doesn't work or only matches some numbers, even when there are multiple numbers in the same format on a page, it will turn some into a link, but not others.
Im in australia using the following regex:
/\b\d\d\d(-|\)\s|\s)\d\d\d-(\d\d\d\d|\w\w\w\w)\b/ig;
However, when I go to http://www.westnet.com.au/phone/contact/ (for example) you will see that there are some 1300 XXX XXX numbers listed on that page, all listed in identical formats.
Only 1 of them is being converted too a link, all the others are being ignored.
Any ideas?
I use this regexp, which captures most Oz phone numbers:
/(((\+61|0) ?[2-9])(( ?[0-9]{4})( ?[0-9]){4}|( ?[0-9]{2})( ?[0-9]){6})|(\s*(\d{4})[- ]?\d{3}[- ]?\d{3}\s*)|(\s*\(?\d{2}\)?[- ]?\d{4}[- ]?\d{4})|[2-9]\d{3} ?\d{4})\b/
It's long, but it works (as the actress said to the bishop). It even works for me on the Westnet web site you mention.
Wouldn't it be nice to have this as a dinky-die Firefox add-on, complete with a configuration dialog where you could select your country/region or supply your own regexp. Perhaps this could help make a start: http://arantius.com/misc/greasemonkey/script-compiler. The down side is that it will no longer work with any of the IE equivalents to greasemonkey, and we'd have to create an IE plug-in.
I've adjusted my copy of the script so that it performs the "replace" (to strip out extra characters) as the page is being marked up rather that when submitting to the CGI. It might load a big page ever so slightly slower, but when you hover on a number you get to see what will actually get sent to the CGI. To do this, replace the 'a.setattribute("href"...' line with:
var cleanMatch = String(match[0]).replace(/[\-\s\/\(\)\.]/g, "");
// here's where we convert into canonical form
cleanMatch=cleanMatch.replace(/^\+61/g, "0");
a.setAttribute("href", "javascript:void("+cleanMatch+")");
I also convert "country code" format (+61 2 nnnnnnnn) into local format (02 nnnnnnnn).
My most desired enhancement would be to pop up a menu to dial, that would also let you select a different telephone extension to use.
Jez
If you look in the script you will see an array which defines the types of element to search in.
If the numbers are not within this type of element (eg <span>) etc then you will need to look at the source and add the elements to the list.
Rick