I worked with the PHP from the end of this post and got it working: How to make a click to call?
<?PHP
$key = $_REQUEST['key'];
$pass = "secret";
if($key == $pass){
#ip address that asterisk is on.
$strHost = "127.0.0.1";
$strUser = "webcall";#specify the asterisk manager username you want to login with
$strSecret = "c5wk8zdkvn3ck5av";#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 = "default";
#specify the amount of time you want to try calling the specified channel before hanging up
$strWaitTime = "30";
#specify the priority you wish to place on making this call
$strPriority = "1";
#specify the maximum amount of retries
$strMaxRetry = "0";
$number=strtolower($_REQUEST['number']);
$pos=strpos ($number,"local");
if ($number == null) :
exit() ;
endif ;
if ($pos===false) :
$errno=0 ;
$errstr=0 ;
$strCallerId = $_REQUEST['cid'];
$oSocket = fsockopen("localhost", 5038, $errno, $errstr, 20);
if (!$oSocket) {
echo "There was a problem<br>\n";
echo "$errstr ($errno)<br>\n";
} else {
echo "Attempting to start<br>\n";
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 ;
}else{
echo "BAD : login details incorrect";
}
?>
The issue I have is that when I hit the end point, it calls the first number correctly, waits to call the second till the first is answered, but the issue is that if the first caller doesn’t answer, it still calls the second number even though there isn’t anyone on the other line.
In my case, I was testing it, and when it called my first phone, I rejected the call, which sent it to voicemail and caused the second call to be made right away.
How can I run it through the AMI or something to detect if a person answers the first call before placing the second? I see it is using the “default” context, but there isn’t really anything in there that seems to be modifiable to do what I am thinking. Honestly I am surprised it works at all when looking at the “default” dialplan.
[default]
exten => _1NXXNXXXXXX,1,Dial(SIP/${EXTEN:${GLOBAL(TRUNKMSD)}}@peer.sipProvider.co)
exten => _NXXNXXXXXX,1,Dial(SIP/${EXTEN:${GLOBAL(TRUNKMSD)}}@peer.sipProvider.co)