Detect answered call in AMI in PHP script

Hi am using this PHP script below and AMI to send voice message.
Is it possible for me to capture one of the variable/values (like Disposition:) under CDR Asterisk Manager event in this php script?
I want to capture the value and store it in the database.

$socket = fsockopen($pbx,“5038”, $errno, $errstr, $timeout); //Connection to AMI
fputs($socket, “Action: Login\r\n”);
fputs($socket, “UserName: username\r\n”);
fputs($socket, “Secret: password\r\n\r\n”);

          fputs($socket, "Action: Originate\r\n" );
          fputs($socket, "Channel: SIP/$dest\r\n" );
          fputs($socket, "Application: Playback\r\n" );
          fputs($socket, "Data: $message\r\n" );               
          fputs($socket, "CallerID: $callerid\r\n" );        
          fputs($socket, "Async: yes\r\n\r\n" ); 
          fputs($socket, "Action: Logoff\r\n\r\n);

sleep (1);
$wrets=fgets($socket,128);

Answer will be represented in channel state events.

Generally, where you can read a channel variable you can also read the result of a dialplan function call.

thanks @david551
Am sorry, am still struggling:
I believe if i forward the call to dialplan i can use exten => s,1,Set(foo=${CDR(disposition)}) to get the value from foo.
I want to avoid forwarding the call to dialplan, so it possible to get the value from this PHP script or i must forward the call to the dialplan?

I would expect:

Action: GetVar
Variable: CDR(disposition)

to work. However, I’d have to trawl the code, or try it, to be sure.

@david551 were you able to give it a try, seem not to be working for me.
After your this suggested code, i tried $thevalue = fgets($sockets) to get the value of the variable but no luck. Or may be i should not use fgets()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.