<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body 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_timestamp)=${STRFTIME(,,%s.%3q)})</tt><tt><br>
</tt><tt> same =>
n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)</tt><tt><br>
</tt><tt><tt> same =>
n,Set(MASTER_CHANNEL(callid_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">EXTEN}@1.1.1.1</a></tt><tt>,,U(answer_handler)b(pre_dial_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_egress)=${SIPCALLID})</tt><tt><br>
</tt><tt> same =>
n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%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_timestamp)=${STRFTIME(,,%s.%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_timestamp)=${STRFTIME(,,%s.%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 class="moz-cite-prefix">On 12/26/2017 03:28 PM, Dovid Bender
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAM3TTh1mj6F1JbUsxxzsFi4rZ+9m8X1LVt3b4BZd8r8JZX31Hg@mail.gmail.com">
<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" moz-do-not-send="true">EXTEN}@1.1.1.1</a>,,U(call-answer-from-carrier))</div>
<div><br>
</div>
<div>Exten => h,1,NoOp(ANSWERED_TIME: ${ANSWEREDTIME}
>>> DIAL_TIME: ${DIALEDTIME} >>>
HANGUP_TIME: ${EPOCH} >>> ANSWERED TIME
${MATH(${EPOCH}-${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="mimeAttachmentHeader"></fieldset>
<br>
</blockquote>
<br>
</body>
</html>