How to pass the answer phone number to AGI script

For call center, the dialplan will queue callers and wait for customer services.
Our CRM needs to get notified when a phone call is bridged using AGI, and need to know
caller Id and answer phone number in order to do some processing.

exten => 2,1,Queue(CustomerService,agi://host:port/callBridged.agi?answerPhone=…)

public class CallBridgedAgiScript extends BaseAgiScript {
public void service(AgiRequest request, AgiChannel channel) throws AgiException {
String callerId = request.getCallerIdNumber();
// how to get the phone number that answered the call ???

  1. how to get the phone number that answered the call inside AGI script?
  2. If I need to pass answer phone as parameter, but answer phone is unknown when the caller is queued.
  3. In addition to registering AGI script with Queue(), are there other ways to get callback when call is bridged?

Thanks for help in advance.

Since the Queue application executes the AGI for the calling channel you should be able to get the channel ID and then, probably using AMI you could get the bridged channel and get the details for that channel. Just an idea.

Thanks for reply.
I looked at AMI commands, but I have not figured out how to get the bridged channel info.
Which AMI command can I get bridged channel?

I also looked at Asterisk-java that has a tutorial called HelloEvents.

public void run() throws IOException, AuthenticationFailedException,
TimeoutException, InterruptedException
// register for events

    // connect to Asterisk and log in

    // request channel state
    managerConnection.sendAction(new StatusAction());
    // wait 10 seconds for events to come in

    // and finally log off and disconnect

public void onManagerEvent(ManagerEvent event)
    // just print received events

Run the HelloEvents example From window XP command, When I dial a number, and get millions of event messages.
But I am only interested in BridgeEvent only.

How to tell Asterisk to send me BridgeEvent only? From HelloEvents output:

2011-10-18 10:45:45 org.asteriskjava.manager.internal.EventBuilderImpl buildEvent
INFO: No event class registered for event type ‘bridge’, attributes: {uniqueid1=1318905937.144, channel1=SIP/Phone801-00
000090, uniqueid2=1318905937.145, channel2=SIP/Phone805-00000091, event=Bridge, privilege=call,all, callerid1=Phone801, b
ridgestate=Link, bridgetype=core, callerid2=805}

Asterisk 1.8.7.

Thanks for help.

you can set channel variable whenever the call is received and use it in AGI/AMI. use the channel ID along with a variable. variables are mapped to channels. so you can use them anytime during the call

In my case I use the following 2 functions in phpagi-asmanager.php to set and retrieve the channel variables:
GetVar() and SetVar()

follow this for more info: … ion+GetVar … ion+SetVar

Thanks for help.
I looked at GetVar and SetVar, but need some explanations.
When a called in Queue is bridged, is there a way to know who answered the phone call?
GetVar/SetVar is for get/set variables in channels, but how can they help to know which channel
is bridged to the call?

Thanks ,


exten => 1,1,Queue(CustomerService,agi://host:port/bridged.agi)
exten => 1,n,Hangup()

Where can I use the variable ${BRIDGEPEER}? Can I access it inside AGI script which is JAVA?
But asterisk-java does not have such API.

Thanks for help.

Use the GetVar AGI method to retrieve the BRIDGEPEER variable.

However, it is possible that BRIDGEPEER is not set until the bridge formation is imminent, in which case you will need to modify the source code of app_queue.c, to set something before it runs the AGI.