<div dir="ltr">It seems that what ever I set in my answer handler does not show up in the hangup handler. In order to do billing I can't rely on the g option where the caller hangs up the call. Looks like I can either use h or a hangup handler along with the shared function.<div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 26, 2017 at 4:40 PM, Eric Wieling <span dir="ltr"><<a href="mailto:ewieling@nyigc.com" target="_blank">ewieling@nyigc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<tt>Don't use an 'h' extension, use a hangup handler. </tt><tt><br>
</tt><tt>Use the MASTER_CHANNEL() function to set variables to
ensure they are always set in the "top most" channel. Below is an
untested example, but is inspired by dialplan code I use in
production. Maybe it will help.<br>
<br>
</tt>
<div><tt>[outbound] ; this is called on the incoming (caller)
channel</tt><tt><br>
</tt></div>
<div><tt>exten => _X.,1,Noop</tt><tt><br>
</tt><tt> same =>
n,Set(MASTER_CHANNEL(start_<wbr>timestamp)=${STRFTIME(,,%s.%<wbr>3q)})</tt><tt><br>
</tt><tt> same =>
n,Set(CHANNEL(hangup_handler_<wbr>push)=hangup_handler,s,1)</tt><tt><br>
</tt><tt><tt> same =>
n,Set(MASTER_CHANNEL(callid_<wbr>ingress)=${SIPCALLID})</tt><tt><br>
</tt>same => n, *** unrelated dialplan, AGIs, etc. ***</tt><tt><br>
</tt><tt> same => n,Dial(SIP/${</tt><tt><a href="mailto:EXTEN%7D@1.1.1.1" target="_blank">EXTEN}@1.1.1.1</a></tt><tt>,,<wbr>U(answer_handler)b(pre_dial_<wbr>handler^s^1)g</tt><tt><br>
</tt><tt> same => n, *** dialplan for the caller when the
callee hangs up first, not run when caller hangs up first. use
it to try dialing another destination, play intercept to caller,
etc. ***</tt><tt><br>
</tt><tt><br>
</tt><tt><br>
</tt><tt>[pre_dial_handler] ; this is called on the outgoing
(callee) channel</tt><tt><br>
</tt><tt>exten => s,1,Noop</tt><tt><br>
</tt><tt> same =>
n,Set(MASTER_CHANNEL(callid_<wbr>egress)=${SIPCALLID})</tt><tt><br>
</tt><tt> same =>
n,Set(MASTER_CHANNEL(dial_<wbr>timestamp)=${STRFTIME(,,%s.%<wbr>3q)})</tt><tt><br>
</tt><tt> same => n,Return</tt><tt><br>
</tt><tt><br>
</tt><tt><br>
</tt><tt>[answer_handler] ; run on outgoing (callee) channel, but
sets answer_timestamp in the caller channel</tt><tt><br>
</tt><tt>exten => s,1,Noop</tt><tt><br>
</tt><tt> same =>
n,Set(MASTER_CHANNEL(answer_<wbr>timestamp)=${STRFTIME(,,%s.%<wbr>3q)})</tt><tt><br>
</tt><tt> same => n,Return</tt><tt><br>
</tt><tt><br>
</tt><tt><br>
</tt><tt>[hangup_handler] ; run on incoming (caller) channel, use
to do final post call cleanup </tt><tt><br>
</tt><tt>
exten => s,1,Noop</tt><tt><br>
</tt><tt>
same =>
n,Set(MASTER_CHANNEL(hangup_<wbr>timestamp)=${STRFTIME(,,%s.%<wbr>3q)})</tt><tt><br>
</tt><tt> same => n, ***post call cleanup AGIs, dialplan, etc.</tt><tt>
***<br>
</tt><tt>
same => n,Return</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><br>
<br>
</div><div><div class="h5">
<div class="m_-3585907076439800804moz-cite-prefix">On 12/26/2017 03:28 PM, Dovid Bender
wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hi,
<div><br>
</div>
<div>I have a dial plan where I need to notify an external
system when a call was answered and when the call hung up. In
both requests the start time needs to be the same. My Dialplan
looks something like this:</div>
<div><br>
</div>
<div><br>
</div>
<div>[outbound]</div>
<div>Exten => _X.,1,Dial(SIP/${<a href="mailto:EXTEN%7D@1.1.1.1" target="_blank">EXTEN}@1.1.1.<wbr>1</a>,,U(call-answer-from-carrier)<wbr>)</div>
<div><br>
</div>
<div>Exten => h,1,NoOp(ANSWERED_TIME: ${ANSWEREDTIME}
>>> DIAL_TIME: ${DIALEDTIME} >>>
HANGUP_TIME: ${EPOCH} >>> ANSWERED TIME
${MATH(${EPOCH}-${<wbr>ANSWEREDTIME},int)})</div>
<div><br>
</div>
<div>[call-answer-from-carrier]</div>
<div>Exten => s,1,Noop(CALL WAS ANSWERED AT ${EPOCH}</div>
<div>Exten => s,n,Agi(some_script.py)</div>
<div><br>
</div>
<div>Now in theory the hangup time of the call (${EPOCH} in the
h extension) minus the answered time should be the same as the
noop from my subroutine. I am finding that some times they
match and some times they are off by a second. My issue is
that the external system expects the answered time to the same
for when we call it from the SubRoutine as well as from the h
extension. I assume the difference is based on the microsecond
of when we look at EPOCH how DIALEDTIME is rounded.</div>
<div><br>
</div>
<div>Any tips on how I can get the same answered time across the
board?</div>
<div><br>
</div>
<div>TIA.</div>
<div><br>
</div>
<div>Dovid</div>
<div><br>
</div>
</div>
<br>
<fieldset class="m_-3585907076439800804mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
<br>
</div></div></div>
</blockquote></div><br></div>