User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

AMI send Call With SayDigits

This is a way to have a website place a call to someone and say numbers to them.
Great for adding extra protection for logging into a web site.
Example: User is prompted with username and password field. after that is correct.
We call their Cell Phone with a 4 Digit pin to finish the login.

Add this to your :/etc/asterisk/extensions_custom.conf

[from-internal-additional]
include => app-say-the-pin


[app-say-the-pin]
exten => 777,1,Answer()
;exten => 777,n,Wait(4)
exten => 777,2(SayPin),Background(incoming-call-1-accept-2-decline)
exten => 777,n(SayPin),Background(incoming-call-1-accept-2-decline)
exten => 777,n(SayPin),Background(incoming-call-1-accept-2-decline)
exten => 777,n(SayPin),Background(incoming-call-1-accept-2-decline)
exten => 777,n(SayPin),Background(incoming-call-1-accept-2-decline)
exten => 777,n(SayPin),Background(incoming-call-1-accept-2-decline)
exten => 777,n(SayPin),Background(incoming-call-1-accept-2-decline)
;exten => 777,3,Goto(app-say-the-pin,777,2)

exten => 1,1,Playback(silence/1)
exten => 1,n,Playback(wait-moment)
;exten => 1,n,Playback(conf-getpin)
exten => 1,n,Playback(silence/2)
exten => 1,n,SayDigits(${yc})
exten => 1,n,Playback(silence/1)
exten => 1,n,Playback(repeater)
exten => 1,n,Playback(silence/1)
exten => 1,n,SayDigits(${yc})
exten => 1,n,Playback(silence/1)
exten => 1,n,Playback(repeater)
exten => 1,n,Playback(silence/1)
exten => 1,n,SayDigits(${yc})
exten => 1,n,Playback(goodbye)
exten => 1,n,Hangup()

exten => 2,1,Playback(goodbye)
exten => 2,n,Hangup()

exten => 3,1,Playback(silence/1)
;exten => 3,n,SayDigits("1 555 5 5 5 1 2 1 2")
exten => 3,n,Playback(letters/c)
exten => 3,n,Playback(letters/o)
exten => 3,n,Playback(letters/m)
exten => 3,n,Playback(letters/p)
exten => 3,n,Playback(letters/a)
exten => 3,n,Playback(letters/n)
exten => 3,n,Playback(letters/y)
exten => 3,n,Goto(app-say-the-pin,777,2)

This is the PHP to send the AMI the code and to call the person.
function CallWithCode($Code,$number){
			$number = str_replace("-","",$number);
			$number = str_replace(".","",$number);
			$number = str_replace(":","",$number);
			$number = str_replace(" ","",$number);

			//connect to AMI strings
			$strHost = "asterisk.box.ipaddress";
			$strUser = "ami_user_name";
			$strSecret = "your_ami_password"; 

			$strChannel = "Local/777@from-internal";
			$strContext = "from-internal";
			$strWaitTime = "10";
			$strPriority = "1";
			$strMaxRetry = "2";
			$strCallerId = "Your Code $Code <$Code>";
			$number= strtolower($number);
			$errno=0 ;
			$errstr=0 ;
			
			if( substr($number,0,3) == "911" ){
				return false;
			}
			if( substr($number,0,3) == "411" ){
				return false;
			}
			if( substr($number,0,4) == "+911" ){
				return false;
			}
			if( substr($number,0,4) == "+411" ){
				return false;
			}

			$oSocket = fsockopen ($strHost, 5038, $errno, $errstr, 10);
			 if (!$oSocket) 
			 {
				return false;
			 } 
			else 
			{
				sleep(1); 
				fputs($oSocket, "Action: login\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, "Context: $strContext\r\n");
				fputs($oSocket, "Exten: $number\r\n");
				fputs($oSocket, "Priority: $strPriority\r\n");
				fputs($oSocket, "WaitTime: $strWaitTime\r\n");
				fputs($oSocket, "CallerId: $strCallerId\r\n");
				fputs($oSocket, "Variable: yc=$Code\r\n");
				fputs($oSocket, "\r\n");
				fputs($oSocket, "Action: Logoff\r\n\r\n");
				sleep(2);
				fclose($oSocket);
			}
	}// END CallWithCode