accessing ANSWEREDTIME AGI variable after the channel hung up.

Feb 20, 2013 at 9:06 AM
Can you access the ANSWEREDTIME AGI variable when the caller hangs up the phone by using AsterNET?

The case is:
  • Caller calls Asterisk with AsterNet FastAGI.
  • In dialplan, somewhere, caller is connected to someone else with Dial() command.
  • During this conversation, when the caller hangs up first, the asterisk channel is DEAD so ANSWEREDTIME variable is not accessible, so it is not possible to measure the length of outdial precisely.
-During this conversation, when the callee hangs up first, then the channel is not dead and the caller continues in dialplan, so ANSWEREDTIME variable is available.

So the problem is: It is not possible in Asterisk 1.4+FastAGI library to measure the length of outdial when the calling party hangs up first.

Any helps will be greatly appreciated! Thank you all!
Mar 15, 2013 at 10:50 AM
ANSWEREDTIME is a Predefined Channel Variable. I am unsure if it's available once the Dial has completed, but I assume it would be. if it is, use GetVariable to retrieve it.
Oct 28, 2014 at 6:25 PM
Interestingly after over a year of this question being sat here and my previous answer not being all that informative, I myself have now run into this same problem!

The issue stems from the fact that any action on a dead channel (one where the caller has hang up) seems to block you from accessing variables, such as the ones required to know if an outbound leg was a) answered and b) how long the call was.

If anyone does have any suggestions on this, it would be greatly appreciated because as yet I've found no good solution to this problem!

Hacked solution 1) Watch AMI and wait for the set var event on the outbound leg channel. This would mean watching AMI from within your FastAGI application and looking for the dial result. This is pretty horrid but so far my only real solution!

Hacked Solution 2) Don't use FastAGI, use Asyng AGI instead. Not 100% sure how this would work, but some sort of wrapper could be created to emulate the normal FastAGI behaviour while using ASync AGI. This would give you the ability to use method 1 in a more structured way... maybe?!
Nov 17, 2014 at 8:32 AM
Can't we see ANSWEREDTIME variable in Hangup Event or CDR event in ami?
Nov 17, 2014 at 11:57 AM
Nov 18, 2014 at 8:33 AM
Yep that's my point why to hack if you can get ANSWEREDTIME through CDR event. Right?
Nov 18, 2014 at 9:05 AM
Yeah, but it's pretty messy. It could be wrapped into the AsterNET.Extensions project. Have some AMI event handled in the Dial extension. Either way, you're dependant on receiving that event. It adds an extra layer of complexity that just shouldn't be there. I'm not saying it's not possible, but it's just nasty! :/