Detect when agent picks up on B party from queue in Asterisk 11

I am working on a development project in Asterisk where I call B party via auto-dialer. When call is answered at B party, call goes to their queue and an announcement is played. Their agents pickup the call in between their announcement. I have to transfer the call to another extension when their agent picks up. I have tried WaitForSilence but their agents don’t even stop for 1 second and if there is no one on the other side, they hangup. I have also tweaked in AMD but there is no success. How can I detect when their agent picks up the call?

I am using Asterisk 11.

You have to write AMI script which will react on BridgeEvent and if it appear then you could RedirectAction to any context, any exten

1 Like

Thanks for your reply przeqpiciel. Actually I am not getting any call event from B party when their agent picks up the call from their queue. That is the problem.

Verify your /etc/asterisk/manager.conf file you should be getting certain events on this action

Thanks for your reply ambiorixg12. Following are the permissions of my manager user.

read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,config,command,reporting,originate,message

How do you connect to AMI ?

I am using a PHP script to connect to AMI.

just to make sure you are not missing an event add the all class to your read line, and verify if still isues will be needed to debug the PHP script and make sure the information it is transmited over the socket

I have added all class in my manager user conf but still no luck. Issue is that I am not getting any event from remote party when their agent picks up the call from their queue.

are you receiving other events ?

Yes. I am receiving all other events.

Here is an example of the events I am receiving:

11:44:17: Event: RTCPReceived
11:44:17: Privilege: reporting,all
11:44:17: From: 172.16.xx.xx:xxxxx
11:44:17: PT: 200(Sender Report)
11:44:17: ReceptionReports: 1
11:44:17: SenderSSRC: 0
11:44:17: FractionLost: 0
11:44:17: PacketsLost: 0
11:44:17: HighestSequence: 6401
11:44:17: SequenceNumberCycles: 0
11:44:17: IAJitter: 7
11:44:17: LastSR: 58926.1036651723919196160
11:44:17: DLSR: 34.9990(sec)

11:44:17: Event: RTCPSent
11:44:17: Privilege: reporting,all
11:44:17: To: 172.16.xx.xx:xxxxx
11:44:17: OurSSRC: 1894187826
11:44:17: SentNTP: 1524066257.3966271488
11:44:17: SentRTP: 1520648
11:44:17: SentPackets: 9422
11:44:17: SentOctets: 1507520
11:44:17: ReportBlock:
11:44:17: FractionLost: 0
11:44:17: CumulativeLoss: 0
11:44:17: IAJitter: 0.0007
11:44:17: TheirLastSR: 3864223217
11:44:17: DLSR: 0.5770 (sec)

This is the list of AMI events, verify which of them the one is the one you are expecting to be fired

I am expecting Newstate. Here is my PHP script to listen to AMI events.

$username = 'manager';
$secret = 'manager123';

$fp = fsockopen("", 5038, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)\n";
else {
                fputs($fp,"Action: login\r\nUsername: ".$username."\r\nSecret: ".$secret."\r\n\r\n");
$line = '';
    while(1) {
                                $read = fread($fp,1);
                                $line .= $read;
                                if ("\n" == $read) {
                                                                                $event_separator = false;
                                                                                if ("\r\n" == $line) {
                                                                                                                                $event_separator = true;
                                                                                echo $line;
                                                                                echo date("H:i:s").":  ";
                                                                                $line = '';


I prefer use PHPAmi for that :slight_smile: