Variables between channels

hello everyone!
How to get variable “ANSWEREDTIME” in “h” extension? which was set in dialAnswerContext subrout?

[dialAnswerContext]
exten => s,1,NoOp()
same => n,Set(__ANSWEREDTIME=${STRFTIME(,%s)})
same => n,Return()

[some_context]
exten => _X.,1,NoOp(external-call)
same => …
same => …
same => n,Dial(SIP/${prefix}${dial_num}@ktrunk,gU(dialAnswerContext)S(${MAX_SPEAK_TIME})

exten => h,1,noop(“extended CDR”)
same => n,NoOp(ANSWEREDTIME = ${ANSWEREDTIME})

You can’t, because the channel containing it no longer exists.

There are mechanisms to set global variables or variables on the master channel for the call.

thank you. maybe there is another way to get time when num B answered the call?

It should be available on the CDR associated with A, unless you answered early.

1 Like

‘ANSWEREDTIME’ is a dial channel variable so you should not set it as you did in ‘dialAnswerContext’ and in the hangup handler. If you just read it in the handler such as Set(tmp=${ANSWEREDTIME}) it will give you the call time.

1 Like

I need to get time when B number pick up the phone

my work solution:

[dialAnswerContext]
exten => s,1,NoOp(chan_name = ${chan_name})
same => n,Set(SHARED(answer_time,${chan_name})=${STRFTIME(,%s)})
same => n,Return()

[some_context]
exten => _X.,1,NoOp(external-call)
same => …
same => …
same => n,Set(__chan_name=${CHANNEL})
same => n,Dial(SIP/${prefix}${dial_num}@ktrunk,gU(dialAnswerContext)S(${MAX_SPEAK_TIME})

exten => h,1,noop(“extended CDR”)
same => n,Set(answer_time=${SHARED(answer_time)})
same => n,NoOp( ${answer_time})

just remember that any transfere will only indicate the last call answer
it is probaly better to use Channel Event Logging (CEL) - Asterisk Project - Asterisk Project Wiki
and add a custom filed where you include the Call-ID form the originating caller (X-CID)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.