<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">My suggestion is to stop trying to do this in the dialplan.  Let asterisk dialplan do it’s job and process the call.  Manage this either through the AMI events and call your scripts from there or if you are using an asterisk version that has ARI then allow it to do your call set up and tear down. Either way don’t over complicate your dialplan.  <br><br><div id="AppleMailSignature">Nathan Kirk</div><div><br>On Dec 27, 2017, at 4:03 AM, Dovid Bender <<a href="mailto:dovid@telecurve.com">dovid@telecurve.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">My issue seems to be that I am using local channels. So for instance if I have:<div><br></div><div><div>[incoming]</div><div>Exten => _X.,1,NooP()</div><div>Exten => _X.,n,Dial(Local/${EXTEN}@out1/n)</div><div>Exten => _X.,n,Dial(Local/${EXTEN}@out2/n)</div><div><br></div><div>Exten => h,1,DumpChan()</div><div><br></div><div><br></div><div>[out1]</div><div>exten => _X.,1,Noop</div><div> same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})</div><div> same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)</div><div> same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})</div><div> same => n,Dial(SIP/1111${<a href="http://EXTEN}@1.1.1.1:5063">EXTEN}@1.1.1.1:5063</a>,,U(answer_handler)b(pre_dial_handler^s^1))</div><div><br></div><div>Exten => h,1,DumpChan()</div><div>[out2]</div><div>exten => _X.,1,Noop</div><div> same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})</div><div> same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)</div><div> same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})</div><div> same => n,Dial(SIP/2222${<a href="http://EXTEN}@1.1.1.1:5063">EXTEN}@1.1.1.1:5063</a>,,U(answer_handler)b(pre_dial_handler^s^1))</div><div><br></div><div>Exten => h,1,DumpChan()</div><div><br></div><div>[pre_dial_handler] ; this is called on the outgoing (callee) channel</div><div>exten => s,1,Noop</div><div> same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})</div><div> same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})</div><div> same => n,Return</div><div><br></div><div><br></div><div>[answer_handler] ; run on outgoing (callee) channel, but sets answer_timestamp in the caller channel</div><div>exten => s,1,Noop</div><div> same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})</div><div> same => n,Return</div><div><br></div><div><br></div><div>[hangup_handler]  ; run on incoming (caller) channel, use to do final post call cleanup</div><div>exten => s,1,Noop</div><div>  same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})</div><div>  same => n,Return</div><div><br></div><div><br></div></div><div><br></div><div><br></div><div>When using MASTER_CHANNEL it sets it on the channel that created the local channel (so it ends up in context incoming and NOT in out1). Not sure if this is a bug since the context incoming is generating the channel that calls out1 that then calls the answer_handler.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 27, 2017 at 4:50 AM, Dovid Bender <span dir="ltr"><<a href="mailto:dovid@telecurve.com" target="_blank">dovid@telecurve.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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="HOEnZb"><div class="h5"><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_tim<wbr>estamp)=${STRFTIME(,,%s.%3q)})</tt><tt><br>
      </tt><tt> same =>
        n,Set(CHANNEL(hangup_handler_p<wbr>ush)=hangup_handler,s,1)</tt><tt><br>
      </tt><tt><tt> same =>
          n,Set(MASTER_CHANNEL(callid_in<wbr>gress)=${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>,,U<wbr>(answer_handler)b(pre_dial_han<wbr>dler^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_eg<wbr>ress)=${SIPCALLID})</tt><tt><br>
      </tt><tt> same =>
        n,Set(MASTER_CHANNEL(dial_time<wbr>stamp)=${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_ti<wbr>mestamp)=${STRFTIME(,,%s.%3q)}<wbr>)</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_ti<wbr>mestamp)=${STRFTIME(,,%s.%3q)}<wbr>)</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="m_2477324455072723909h5">
    <div class="m_2477324455072723909m_-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}-${ANSWEREDTIME<wbr>},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_2477324455072723909m_-3585907076439800804mimeAttachmentHeader"></fieldset>
      <br>
    </blockquote>
    <br>
  </div></div></div>

</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>-- </span><br><span>_____________________________________________________________________</span><br><span>-- Bandwidth and Colocation Provided by <a href="http://www.api-digital.com">http://www.api-digital.com</a> --</span><br><span></span><br><span>Check out the new Asterisk community forum at: <a href="https://community.asterisk.org/">https://community.asterisk.org/</a></span><br><span></span><br><span>New to Asterisk? Start here:</span><br><span>      <a href="https://wiki.asterisk.org/wiki/display/AST/Getting+Started">https://wiki.asterisk.org/wiki/display/AST/Getting+Started</a></span><br><span></span><br><span>asterisk-users mailing list</span><br><span>To UNSUBSCRIBE or update options visit:</span><br><span>   <a href="http://lists.digium.com/mailman/listinfo/asterisk-users">http://lists.digium.com/mailman/listinfo/asterisk-users</a></span></div></blockquote></body></html>