(PJSIP) Getting call-id and duration of the outbound leg


My scenario is rather simple (all programmed as an AGI script):

  1. Receive an IB call (that invokes the AGI script)
  2. Answer
  3. Plays some short announcement
  4. Make outbound call

I have 2 issues

  1. When the OB call hangs up, I’m trying to get content of the BRIDGEPVTCALLID variable but seems to be always empty however when i do core show channel <channel_id> , the correct value is there.
    Also, the variable is not populated in DumpChan()

  2. I cannot get the duration of the OB leg. ANSWEREDTIME as well as CDR(billsec) have duration of the whole call (including the IB leg)
    The only way seems to work is to call a Local channel that calls the PJSIP, instead of calling PJSIP channel directly

so 2 questions:

  1. How access the Call-ID if the outbound leg?
  2. What’s the right procedure of getting correct duration of the outbound leg?

media-dev*CLI> core show version
Asterisk certified/13.21-cert2 built by root @ media2.dev on a x86_64 running Linux on 2018-06-14 16:56:27 UTC