Click to Dial or php API to dial from asterisk

  Asterisk

PHP script for click to dial or API to dial from asterisk via http

source :  Elastix forum

copy the below code to a file (call.php)  to the webdirectory.

executes as  :  http://ipaddress/call.php??exten=SIP/100&number=9999999999

<?php

#ip address that asterisk is on.
$strHost = “127.0.0.1”;
$strUser = “admin”;#specify the asterisk manager username you want to login with
$strSecret = “elastix456”;#specify the password for the above user
#specify the channel (extension) you want to receive the call requests with
#e.g. SIP/XXX, IAX2/XXXX, ZAP/XXXX, etc
# $strChannel = “SIP/100”;
$strChannel = $_REQUEST[‘exten’];
$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”);
sleep(2);
fclose($oSocket);
}
echo “Extension $strChannel should be calling $number.” ;
else :
exit() ;
endif ;
?>
Using this script for click to dial number in mozilla firefox.

1. Install the Telify  addon to the mozilla

2. then configure it as shown in below picture

  1. used protocal- Custom URL
  2. Custom URL – https://192.168.1.2/call.php?exten=222&number=$0
  3. apply or ok

once done , any numbers in the webpage or mail  will be highlighted fro click to dial.

LEAVE A COMMENT