PHP script not executing when calls come through Queue

Hi every one,

I am new to Asterisk. I am building an application in which callers call a queue number (in my condition the queue number is 5555). The queue transfers the calls to the avaliable agent. (agents logs in to the queue through AgentLogin() function.)

It all works fine.

I want to run a PHP code when the agent gets a call through queue. For Direct calls the PHP code runs fine. Please see both the cases described below. CASE:1 is fine, the problem is in CASE:2.
My extensions.conf has got:
[b]
extensions.conf:

exten => 1234,1,Answer()
exten => 1234,n,AGI(agiThePhpCode.php)
exten => 1234,n,Dial(SIP/${EXTEN},15)[/b]

Where: ‘1234’ is the agent extension, and ‘agiThePhpCode.php’ is the PHP file.

CASE 1: (ext:6789 dials ext:1234) - WORKS FINE

1234 answers the call.
agiThePhpCode.php executes.
1234 phone rings (for 15 sec)

PROBLEM: No problem, every thing is working as expected.

CASE 2: (ext:6789 dials queue:5555, where ext:1234 is logged in as agent)

1234 is logged in and music is playing in the headset.
6789 calls 5555
5555 transfers the call to 1234
1234 listens a beep
1234 automatically answers the call
6789 and 1234 are now talking to each other.

PROBLEM: in this CASE agiThePhpCode.php didnt execute.

If any body can please let me know how to execute the agiThePhpCode.php in the CASE:2 Senario.

Regards,
Immortalali

Pass the agi as a parameter to the queue application.

Queue(queuename[|options[|URL][|announceoverride][|timeout][|AGI]):

Hi there again,

thanks for the solution. it did worked.

My php code is executing.

but there is another issue…i used to send some channel variables to the php code…

e.g:

exten=>1234,n,AGI(agiThePhpCode.php,${CDR(src)},${CDR(dst)},${CDR(dcontext)},${CDR(clid)},${CDR(channel)},${CDR(dstchannel)})

If 6789 calls 1234 directly, the senario is:

6789 calls 1234
php code executes
php code receives a value of 6789 in source through ${CDR(src)}
php code receives a value of 1234 in destination ${CDR(dst)}
1234 phone rings

if 6789 calls 5555 and 5555 directs the call to 1234, the senario is:

6789 calls 5555
php code executes
php code receives a value of 6789 in source through ${CDR(src)}
php code receives a value of 5555 in destination through ${CDR(dst)}
5555 directs the call to 1234
1234 music on hold stops
1234 answers automatically.

the reason i wanted my php code to work, was to get the agent number to whom the queue (5555) will forward the call. The solution you provided did work, but it doesn’t sends the agent number to the php code. it send the queue number i.e. 5555 to the php.

is there any way i can get the number of the agent to whom the call will be forwarded by the queue. or even after the call is forwarded can i get the number of the agent who just got the call from the queue.???

Thanks in advance.

please if it cannot be done this way, let me know any other possible way.

Thanks Allot.

In queues.conf, add this parameter in the general section.

setinterfacevar=yes

Then in your php, grab the MEMBERINTERFACE channel variable for the agent the queue is connecting to. We use this for screen pops for some of our clients.

Sorry I didnt got eactly waht you said.

You mean I should first add the following line under general in my queues.conf:

setinterfacevar=yes

and then when i call the php script through agi i should send a channel variable MEMBERINTERFACE which makes the whole statement in extensions.conf like this:

exten=>5555,n,Queue(callsInQueue|tThH|||100|agiThePhpCode.php,${CDR(src)},${CDR(dst)},${CDR(memberinterface)}))

the php script should read the channel variable as it do for the ‘src’ and ‘dst’. (after making the ammendments in it)

did i got u right???

Not exactly. Inside the php, do something like this:
(This is perl code, but php is similar iirc)

my $memberinterface = $AGI->get_variable(‘MEMBERINTERFACE’);

Then use that variable instead of the dst arg

Hi,

i tried reading the value of MEMBERINTERFACE after passing it through the chanelvariable

i.e.:

exten=>5555,n,Queue(callsInQueue|tThH|||100|agiThePhpCode.php,${CDR(src)},${CDR(dst)},${CDR(memberinterface)})

and then i read the values in php as i did for src and dst,

the php code executes, i get the values of src and dst, but the mmbetinterface is empty.

The perl code you provided i tried that, but i think that wont work as it is in php, thats why the php code didnt executed at all when i tried it.

i dont know its php counterpart, so googled a bit for it and foud some thing else. please have a look at it.

“That is highly dependent on when you attempt to get the value. The
MEMBERINTERFACE variable is set once a member has answered the call, so if you
are running your AGI before that, then MEMBERINTERFACE will be empty. One option
you have is to pass the name of an AGI script as the sixth argument to Queue().
This AGI will run between when the member answers the call and when the call is
bridged. At that point, the MEMBERINTERFACE variable will be populated with the
correct string.”

WHT does he mean by SIXTH ARGUMENT???..doest that make any sense…???

let me know if u get hand on your perl code’s php counterpart.

and if the message above i got from google search makes any sense then please let me knoe how to apply it.

Great;ly appreciating your help.

thanks alot.

Your problem is that you are using ${CDR(memberinterface)} as a parameter to the agi… That value doesn’t exist so it won’t work. The agent the queue is sending the call into is not known at the time the caller enters the queue. So you will not be able to pass it into the queue application. The AGI application is executed when the bridge between the Agent and the Caller is made (In easier terms, when the agent answers the phone). You need to read in the MEMBERINTERFACE variable inside your php script when it is looking for the agent the call was connected to.

Look in the php libraries documentation for how to do that. Maybe here: phpagi.sourceforge.net/phpagi2/d … t_variable?

Alrite, that was clear enough. I got what u meant.

I tried the following in my PHP:

$memberinterface = $agi->(“MEMBERINTERFACE”);

RESULT: php code does not execute. (Probably a syntax error)

$memberinterface = $AGI->get_variable(‘MEMBERINTERFACE’);

RESULT: php code does not execute. (Probably a syntax error)

I looked out at google…found some one with the same problem. but no body has given any answers to it.

I know this might not be the right place to ask about this syntax/php issus…but if you, or any one else who comes here and read this post, please let me know HOW I CAN RETRIEVE MBERINTERFACE VALUE IN PHP CODE.

Once again thanks allot for your help and consideration.

Regards,
Immortalali.