TAPI Click-To-Dial possible?

OK, I got this figured out in a great way. I adapted the script above quite heavily. It was first of all very old.

The method is that the script uses a registry entry to call an external url with the highlighted text, so it calls o.php on the server, which then takes the highlighted text, trims is and send it to p.php, which sends the dial command to the management API. I adapted it to not open a window when you dial, to properly trim non-digit characters, and to add a 1 in front of numbers that are 10 digits. In addition, I made it so that you can send a prefix as an URL variable, so you can easily configure multiple right-click entries in Internet Explorer to dial various outgoing lines, i.e. you can have one entry for “Dial Home Line” and one for “Dial Business Line” which might add a 9 in front.

In var/www/html/clicktocall (clicktocall is a new directory), create a file called “o.php” containing the following:


<script language="javascript"> 
       var hlobj = external.menuArguments.window.document.selection; 
       var hlrng = hlobj.createRange();
       var hlarg = hlrng.text; 

       hlarg = hlarg.replace(/[^\d]/g, "");
       if (hlarg.length==10 && hlarg.charAt(0)!="1") hlarg = "1" + hlarg;

       var url="http://asterisk.mydomain.com/clicktocall/p.php?n=" + hlarg + "&x=<? echo $_REQUEST['x']; ?>" + "&p=<? echo $_REQUEST['p']; ?>";

//     location.replace(url);

       function makeRequest(url) { 

         if (window.XMLHttpRequest) { // Mozilla, Safari,... 
             http_request = new XMLHttpRequest(); 
         } else if (window.ActiveXObject) { // IE 
             http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
         } 
         http_request.open('GET', url, true); 
         http_request.send(null); 

       } 
       makeRequest(url);

</script>

Next, in the same directory, create a file called “p.php”, containing the following:


<html> 
<head> 
<title>Dialing...</title> 
</head> 
<body style="background: blue; color: yellow; font: 12pt bold sans-serif;"> 
<pre> 
<? 

if (( !empty( $_REQUEST['n'] ) ) && ( !empty( $_REQUEST['x'] ) ) ) 
{ 
       $num = $_REQUEST['n']; 
       $ext = $_REQUEST['x']; 
       $pre = $_REQUEST['p'];

       $num = preg_replace( "/\D/", "", $num ); 
       $num = $pre . $num;

       if ( ! empty( $num ) ) 
       { 
               echo "Dialing $num\r\n"; 

               $timeout = 10; 
               $asterisk_ip = "127.0.0.1"; 

               $socket = fsockopen($asterisk_ip,"5038", $errno, $errstr, $timeout); 
               fputs($socket, "Action: Login\r\n"); 
               fputs($socket, "UserName: admin\r\n"); 
               fputs($socket, "Secret: elastix456\r\n\r\n"); 

               $wrets=fgets($socket,128); 

               echo $wrets; 

               fputs($socket, "Action: Originate\r\n" ); 
               fputs($socket, "Channel: SIP/$ext\r\n" ); 
               fputs($socket, "Exten: $num\r\n" ); 
               fputs($socket, "Variable: _SIPADDHEADER55=Call-Info: answer-after=0\r\n" );
                fputs($socket, "Context: from-internal\r\n" );
	       fputs($socket, "CallerId: Dialing <$num>\r\n"); 
               fputs($socket, "Priority: 1\r\n" ); 
               fputs($socket, "Async: yes\r\n\r\n" ); 

               $wrets=fgets($socket,128); 
               echo $wrets; 
       } 
       else 
       { 
               echo "Unable to determine number from (" . $_REQUEST['n'] . ")\r\n"; 
       } 
} 
else 
{?> 
Please enter a number to dial. 
<?} 

?> 
</pre> 
</body> 
</html> 


(change relevant variables).

Next create the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Dial Business Line
For the Default, enter the URL “http://asterisk.mydomain.com/clicktocall/o.php?x=210&p=9
… where x is the extension you want to ring with the dialed called, and p is the prefix to add.
Add a Hex key called “Contexts” with the value of 0x10

Create another registry key called:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Dial Home Line
Do the same as above for Default and Contexts, except omit the &p=9 part of the URL so no prefix is dialed.

This of course assumes a setup where the phone is a home phone unless you dial 9, in which case it’s a business phone.

You can now highlight any phone number on a web-page, right-click, and have the number dialed on your phone using any outgoing line of your choice.

I’m trying to find out if there’s a way I can also automatically activate speakerphone, because you otherwise either have to activate it yourself or you have to pick up the phone to start ringing the number. I’ve tried various ways of inserting *80, but it somehow doesn’t do it.

Anyway, try it out. It works like a charm here.

Per