[SOLVED]Get SIP Agent number / username after hangup

Im trying to get the SIP Username / Agent number after the call has hung up. The following is my extensions.conf relevent information:

[sub-queue]
exten => h,1,AGI(queue-answered.php,${AGENTNUMBER},${SIP_HEADER(username)},${SIPUSERAGENT},55)
exten => s,2,ExecIf($["${ARG1}"="msg"]?Playback(adro/record-warning))
;same => n,AGI(queue-answered.php,55)
;same => n,AGI(queue-answered.php,${AGENTNUMBER})
;same => n,AGI(queue-answered.php,${SIP_HEADER(username)})
;exten => h,AGI(queue-answered.php,${AGENTNUMBER})

same => n,Queue(someQueue,tk,,,150)
;exten => h,1,AGI(queue-answered.php,${AGENTNUMBER})

same => n,Dial(SIP/CL/${ANSWERINGNUM})

same => n,Return()

And the AGI script calls:

foreach($argv as $t=>$l) {log_agi("Got $t=$l");}

Which displays:

-- Launched AGI Script /var/lib/asterisk/agi-bin/queue-answered.php queue-answered.php,,,,55: queue-answered.php,,,,55: Got 0=/var/lib/asterisk/agi-bin/queue-answered.php queue-answered.php,,,,55: Got 1= queue-answered.php,,,,55: Got 2= queue-answered.php,,,,55: Got 3= queue-answered.php,,,,55: Got 4=55

This means that all the variables in the params are blank… Except for the 55 which i put there to show that it is working

So how do you catch the agent who picked up the call within Extensions.conf?

Thanks in advance :smile:

(Btw, cant use CDR for a variety of reasons)

Using Asterisk 1.8 from source. Addon pack installed.

Ok i found the solution on my own eventually, when i was trying to find the solution this thread kept coming up :stuck_out_tongue: So ill post the solution so others can benefit…

What I did to get the data is:

Use the CDR variable (but not the CDR itself), to retrieve the value via “${CDR(dstchannel)}”.

Broken down:
exten => h, is the event of hangup
AGI( , in older asterisk it used to be DeadAGI for hanged up calls, this is no longer the case, always use AGI.
,${CDR(dstchannel)} , This is the destination channel, ie, the SIP agent :smile:

The argv[1] variable will look something like this:
“SIP/1065-0000041d”

Very messy

With my php AGi script I did:

$matchs = 0;
preg_match("[SIP/\d*]",$argv[1],$matchs);
$tmp = $matchs[0];
$uid = str_replace("SIP/","",$tmp);

This results in purely the SIP agent ID without any other extraneous bits and pieces(1065).

Hope that helps :smile:

So are you saying that once the call is sent to the hangup extension (h) it looses all the channel variables etc?

If that’s the case, why not just collect them before the call is hung up. like:

same => n,Set(MYUSERNAME=${SIP_HEADER(username)})
; dial, queue,
; etc, etc,
exten => h,1,AGI(queue-answered.php,${MYUSERNAME})

That was my first idea to but…

The problem is it doesn’t know WHO picked up until the call has been picked up (and to my knowledge you cant do much once the call is fully connected between SIP Client and phone call originator, but then again i am a noob :smile: )

So one has to wait until the call has hanged up in order to get the SIP user agent information.

PS: At the very least in my case, its queue based answering with 200+ SIP clients across 9 different queues. It may be different on a smaller scale without queues.

Although on a side note, one of the AGI variables every now and then does an odd thing, the variable $agi_calleridname , which in my extension script always gets forcefully modified from the originator to be a correct human readable line name. Which I’m using to record the line, but every now and then it changes its behavior to be the caller id of the person who picked up. Very easy to fix, but i just thought i would mention it… Is it when a certain client hangs up first? Or…?

Ok, well so long as it works for you.

Just btw, if you are interested there are a bunch of other things you can do before and after entering a queue. Take a look here:
voip-info.org/wiki/view/Aste … ueues.conf

There are some cool things like maco’s that you can run etc. And also you can get the Queue Log -that’s actually go quite a lot of information about queues. I found this to most useful - and you can use queu_log in RealTime using say MySQL. It does 99% of the job for you… all you need to do is present the data logically.