Super Technologies

Click to Call Script
Written by Administrator
Friday, 14 July 2006
Asterisk Extras is please to present the Asterisk Click to Call PHP script. This was adapted from work done from the voipjots.com folks.

2006-10-23 Download the latest click to call app here. This new version allows for every extension to utilize C2C by setting a cookie with there extension info in it and calling it when passing the call on. If the cookie is not set it will as for your SIP extension number and will procced to a link to click the call. After the cookie is set it should pass the call on normally.

2006-09-21
Update: Some have had an issue with the click to call script not working properly and the reason is because it is being processed to fast when the call goes to the manager. Add a sleep statement like so:

sleep(2);

before

fclose($oSocket);

Also is you want to specify an extension rather than hard code one in the file you can do that by changing:

$strChannel = “SIP/502”;

to

$strChannel = $_REQUEST[‘exten’];

and then your URL will look like:

http://10.72.126.137/c2c.php?exten=SIP/205&number=15185551212

2006-07-19
Update: The Grease Monkey script now translates phone numbers that have letters in them. So a page with 1-800-555-TELL will now work.

Thanks to oOo over at the Devshed Forums for the help.

Essentially I was looking for a way to hook up my PHP Addressbook with Asterisk. Some of the click to call scripts out there didn’t do what I wanted them to do because they either required using Outlook with a tapi application or having to enter in a phone number in a box and click submit.

What we needed was for us to be able to click on an phone number and it fire off to our Asterisk server and my extensions would ring and then it would dial the number. Below is the code that makes it all possible.

<?php
// Copyright 2006 Baldwin Technology Solutions, Inc.
// Requires Asterisk, Apache, and PHP. Place this file
// onto your apache server and call the URL like so
// http://yourapacheserver/c2c.php?number=15185551234
// A page will display that it is calling your extension and
// what number it is calling.
// On the callerid on the phone it will show Web Call 15185551234
#ip address that asterisk is on.$strHost = “127.0.0.1”;#specify the username you want to login with (these users are defined in /etc/asterisk/manager.conf)#this user is the default AAH AMP user; you shouldn’t need to change, if you’re using AAH.$strUser = “admin”;#specify the password for the above user
$strSecret = “amp111”;

#specify the channel (extension) you want to receive the call requests with
#e.g. SIP/XXX, IAX2/XXXX, ZAP/XXXX, etc
$strChannel = “SIP/502”;

#specify the context to make the outgoing call from. By default, AAH uses from-internal
#Using from-internal will make your outgoing dialing rules apply
$strContext = “from-internal”;

#specify the amount of time you want to try calling the specified channel before hangin up
$strWaitTime = “30”;

#specify the priority you wish to place on making this call
$strPriority = “1”;

#specify the maximum amount of retries
$strMaxRetry = “2”;

$number=strtolower($_REQUEST[‘number’]);
$pos=strpos ($number,”local”);
if ($number == null) :
exit() ;
endif ;
if ($pos===false) :
$errno=0 ;
$errstr=0 ;
$strCallerId = “Web Call <$number>”;
$oSocket = fsockopen (“localhost”, 5038, &$errno, &$errstr, 20);
if (!$oSocket) {
echo “$errstr ($errno)<br>\n”;
} else {
fputs($oSocket, “Action: login\r\n”);
fputs($oSocket, “Events: off\r\n”);
fputs($oSocket, “Username: $strUser\r\n”);
fputs($oSocket, “Secret: $strSecret\r\n\r\n”);
fputs($oSocket, “Action: originate\r\n”);
fputs($oSocket, “Channel: $strChannel\r\n”);
fputs($oSocket, “WaitTime: $strWaitTime\r\n”);
fputs($oSocket, “CallerId: $strCallerId\r\n”);
fputs($oSocket, “Exten: $number\r\n”);
fputs($oSocket, “Context: $strContext\r\n”);
fputs($oSocket, “Priority: $strPriority\r\n\r\n”);
fputs($oSocket, “Action: Logoff\r\n\r\n”);
fclose($oSocket);
}
echo “Extension $strChannel should be calling $number.” ;
else :
exit() ;
endif ;
?>

Edit the lines needed for your setup and place the file on a apache web server with PHP installed.

Call the webpage like so:

http://yourserver/c2c.php?number=15555555555

Click to Call from Firefox with a Grease Monkey Script.

If you use Firefox as your browser of choice like I do, then you can also install our Grease Monkey script to enable phone numbers to be clicked on in Firefox and have them sent to the Click to Call script above.

So what do we need to get this to work? I’m glad you asked.

1. Install the Grease Monkey Extension for Firefox from here .

2. Download our Grease Monkey script from here.

3. Change the IP address in the TXT file in notepad and save the file as cc.user.js
A. Make sure word wrapping is off.

4. In Firefox go to Tools> New User Script and browse to where you saved the cc.user.js script.

5. Once installed refresh this page and the phone 800-555-1212 should be a link now pointing to your Asterisk Server.

If you have any questions let us know.

Enjoy