Re: [asterisk-users] Answered time on channel

2018-01-02 Thread Steve Edwards

  On Tue, 26 Dec 2017, Eric Wieling wrote:

Don't use an 'h' extension, use a hangup handler.  



On 12/26/2017 04:43 PM, Steve Edwards wrote:

  Why?


On Tue, 2 Jan 2018, Eric Wieling wrote:


From the hangup handler specification:


Hangup handlers are an alternative to the h extension. They can be used 
in addition to the h extension. The idea is to attach a Gosub routine to 
a channel that will execute when the call hangs up. Whereas which h 
extension gets executed depends on the location of dialplan execution 
when the call hangs up, hangup handlers are attached to the call 
channel. You can attach multiple handlers that will execute in the order 
of most recently added first.


Cool. So in my case where every context has:

exten = h,1,goto(finish-call,h,1)

a hangup handler established at the start of the call makes perfect sense 
and prevents stupid errors like forgetting to list the template in the 
context declaration.


--
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
https://www.linkedin.com/in/steve-edwards-4244281-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Answered time on channel

2018-01-02 Thread Eric Wieling

From the hangup handler specification:

Hangup handlers are an alternative to the h extension. They can be used 
in addition to the h extension. The idea is to attach a Gosub routine to 
a channel that will execute when the call hangs up. Whereas which h 
extension gets executed depends on the location of dialplan execution 
when the call hangs up, hangup handlers are attached to the call 
channel. You can attach multiple handlers that will execute in the order 
of most recently added first.


On 12/26/2017 04:43 PM, Steve Edwards wrote:

On Tue, 26 Dec 2017, Eric Wieling wrote:


Don't use an 'h' extension, use a hangup handler.


Why?





-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Answered time on channel

2017-12-27 Thread nathan Kirk
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.  

Nathan Kirk

> On Dec 27, 2017, at 4:03 AM, Dovid Bender  wrote:
> 
> My issue seems to be that I am using local channels. So for instance if I 
> have:
> 
> [incoming]
> Exten => _X.,1,NooP()
> Exten => _X.,n,Dial(Local/${EXTEN}@out1/n)
> Exten => _X.,n,Dial(Local/${EXTEN}@out2/n)
> 
> Exten => h,1,DumpChan()
> 
> 
> [out1]
> exten => _X.,1,Noop
>  same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
>  same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
>  same => 
> n,Dial(SIP/${EXTEN}@1.1.1.1:5063,,U(answer_handler)b(pre_dial_handler^s^1))
> 
> Exten => h,1,DumpChan()
> [out2]
> exten => _X.,1,Noop
>  same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
>  same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
>  same => 
> n,Dial(SIP/${EXTEN}@1.1.1.1:5063,,U(answer_handler)b(pre_dial_handler^s^1))
> 
> Exten => h,1,DumpChan()
> 
> [pre_dial_handler] ; this is called on the outgoing (callee) channel
> exten => s,1,Noop
>  same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})
>  same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Return
> 
> 
> [answer_handler] ; run on outgoing (callee) channel, but sets 
> answer_timestamp in the caller channel
> exten => s,1,Noop
>  same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Return
> 
> 
> [hangup_handler]  ; run on incoming (caller) channel, use to do final post 
> call cleanup
> exten => s,1,Noop
>   same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})
>   same => n,Return
> 
> 
> 
> 
> 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.
> 
> 
> 
> 
> 
> 
>> On Wed, Dec 27, 2017 at 4:50 AM, Dovid Bender  wrote:
>> 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.
>> 
>> 
>> 
>>> On Tue, Dec 26, 2017 at 4:40 PM, Eric Wieling  wrote:
>>> Don't use an 'h' extension, use a hangup handler.   
>>> 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.
>>> 
>>> [outbound] ; this is called on the incoming (caller) channel
>>> exten => _X.,1,Noop
>>>  same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
>>>  same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
>>>  same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
>>>  same => n, *** unrelated dialplan, AGIs, etc. ***
>>>  same => 
>>> n,Dial(SIP/${EXTEN}@1.1.1.1,,U(answer_handler)b(pre_dial_handler^s^1)g
>>>  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. ***
>>> 
>>> 
>>> [pre_dial_handler] ; this is called on the outgoing (callee) channel
>>> exten => s,1,Noop
>>>  same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})
>>>  same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})
>>>  same => n,Return
>>> 
>>> 
>>> [answer_handler] ; run on outgoing (callee) channel, but sets 
>>> answer_timestamp in the caller channel
>>> exten => s,1,Noop
>>>  same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})
>>>  same => n,Return
>>> 
>>> 
>>> [hangup_handler]  ; run on incoming (caller) channel, use to do final post 
>>> call cleanup 
>>> exten => s,1,Noop
>>>   same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})
>>>   same => n, ***post call cleanup AGIs, dialplan, etc. ***
>>>   same => n,Return
>>> 
>>> 
>>> 
 On 12/26/2017 03:28 PM, Dovid Bender wrote:
 Hi,
 
 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:
 
 
 [outbound]
 Exten => _X.,1,Dial(SIP/${EXTEN}@1.1.1.1,,U(call-answer-from-carrier))
 
 Exten => 

Re: [asterisk-users] Answered time on channel

2017-12-27 Thread Dovid Bender
Seems I hit this: https://issues.asterisk.org/jira/browse/ASTERISK-23133

On Wed, Dec 27, 2017 at 5:03 AM, Dovid Bender  wrote:

> My issue seems to be that I am using local channels. So for instance if I
> have:
>
> [incoming]
> Exten => _X.,1,NooP()
> Exten => _X.,n,Dial(Local/${EXTEN}@out1/n)
> Exten => _X.,n,Dial(Local/${EXTEN}@out2/n)
>
> Exten => h,1,DumpChan()
>
>
> [out1]
> exten => _X.,1,Noop
>  same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
>  same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
>  same => n,Dial(SIP/${EXTEN}@1.1.1.1:5063
> ,,U(answer_handler)b(pre_dial_handler^s^1))
>
> Exten => h,1,DumpChan()
> [out2]
> exten => _X.,1,Noop
>  same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
>  same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
>  same => n,Dial(SIP/${EXTEN}@1.1.1.1:5063
> ,,U(answer_handler)b(pre_dial_handler^s^1))
>
> Exten => h,1,DumpChan()
>
> [pre_dial_handler] ; this is called on the outgoing (callee) channel
> exten => s,1,Noop
>  same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})
>  same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Return
>
>
> [answer_handler] ; run on outgoing (callee) channel, but sets
> answer_timestamp in the caller channel
> exten => s,1,Noop
>  same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Return
>
>
> [hangup_handler]  ; run on incoming (caller) channel, use to do final post
> call cleanup
> exten => s,1,Noop
>   same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})
>   same => n,Return
>
>
>
>
> 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.
>
>
>
>
>
>
> On Wed, Dec 27, 2017 at 4:50 AM, Dovid Bender  wrote:
>
>> 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.
>>
>>
>>
>> On Tue, Dec 26, 2017 at 4:40 PM, Eric Wieling  wrote:
>>
>>> Don't use an 'h' extension, use a hangup handler.
>>> 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.
>>>
>>> [outbound] ; this is called on the incoming (caller) channel
>>> exten => _X.,1,Noop
>>>  same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
>>>  same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
>>>  same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
>>>  same => n, *** unrelated dialplan, AGIs, etc. ***
>>>  same => n,Dial(SIP/${EXTEN}@1.1.1.1,,U(answer_handler)b(pre_dial_han
>>> dler^s^1)g
>>>  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. ***
>>>
>>>
>>> [pre_dial_handler] ; this is called on the outgoing (callee) channel
>>> exten => s,1,Noop
>>>  same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})
>>>  same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})
>>>  same => n,Return
>>>
>>>
>>> [answer_handler] ; run on outgoing (callee) channel, but sets
>>> answer_timestamp in the caller channel
>>> exten => s,1,Noop
>>>  same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})
>>>  same => n,Return
>>>
>>>
>>> [hangup_handler]  ; run on incoming (caller) channel, use to do final
>>> post call cleanup
>>> exten => s,1,Noop
>>>   same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})
>>>   same => n, ***post call cleanup AGIs, dialplan, etc. ***
>>>   same => n,Return
>>>
>>>
>>>
>>> On 12/26/2017 03:28 PM, Dovid Bender wrote:
>>>
>>> Hi,
>>>
>>> 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:
>>>
>>>
>>> [outbound]
>>> Exten => _X.,1,Dial(SIP/${EXTEN}@1.1.1.1,,U(call-answer-from-carrier))
>>>
>>> Exten => h,1,NoOp(ANSWERED_TIME: ${ANSWEREDTIME} >>> DIAL_TIME:
>>> ${DIALEDTIME} >>> HANGUP_TIME: ${EPOCH} >>> ANSWERED TIME
>>> ${MATH(${EPOCH}-${ANSWEREDTIME},int)})
>>>
>>> [call-answer-from-carrier]
>>> Exten => s,1,Noop(CALL WAS ANSWERED AT ${EPOCH}
>>> Exten => s,n,Agi(some_script.py)
>>>
>>> Now in theory 

Re: [asterisk-users] Answered time on channel

2017-12-27 Thread Dovid Bender
My issue seems to be that I am using local channels. So for instance if I
have:

[incoming]
Exten => _X.,1,NooP()
Exten => _X.,n,Dial(Local/${EXTEN}@out1/n)
Exten => _X.,n,Dial(Local/${EXTEN}@out2/n)

Exten => h,1,DumpChan()


[out1]
exten => _X.,1,Noop
 same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
 same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
 same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
 same => n,Dial(SIP/${EXTEN}@1.1.1.1:5063
,,U(answer_handler)b(pre_dial_handler^s^1))

Exten => h,1,DumpChan()
[out2]
exten => _X.,1,Noop
 same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
 same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
 same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
 same => n,Dial(SIP/${EXTEN}@1.1.1.1:5063
,,U(answer_handler)b(pre_dial_handler^s^1))

Exten => h,1,DumpChan()

[pre_dial_handler] ; this is called on the outgoing (callee) channel
exten => s,1,Noop
 same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})
 same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})
 same => n,Return


[answer_handler] ; run on outgoing (callee) channel, but sets
answer_timestamp in the caller channel
exten => s,1,Noop
 same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})
 same => n,Return


[hangup_handler]  ; run on incoming (caller) channel, use to do final post
call cleanup
exten => s,1,Noop
  same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})
  same => n,Return




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.






On Wed, Dec 27, 2017 at 4:50 AM, Dovid Bender  wrote:

> 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.
>
>
>
> On Tue, Dec 26, 2017 at 4:40 PM, Eric Wieling  wrote:
>
>> Don't use an 'h' extension, use a hangup handler.
>> 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.
>>
>> [outbound] ; this is called on the incoming (caller) channel
>> exten => _X.,1,Noop
>>  same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
>>  same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
>>  same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
>>  same => n, *** unrelated dialplan, AGIs, etc. ***
>>  same => n,Dial(SIP/${EXTEN}@1.1.1.1,,U(answer_handler)b(pre_dial_han
>> dler^s^1)g
>>  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. ***
>>
>>
>> [pre_dial_handler] ; this is called on the outgoing (callee) channel
>> exten => s,1,Noop
>>  same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})
>>  same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})
>>  same => n,Return
>>
>>
>> [answer_handler] ; run on outgoing (callee) channel, but sets
>> answer_timestamp in the caller channel
>> exten => s,1,Noop
>>  same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})
>>  same => n,Return
>>
>>
>> [hangup_handler]  ; run on incoming (caller) channel, use to do final
>> post call cleanup
>> exten => s,1,Noop
>>   same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})
>>   same => n, ***post call cleanup AGIs, dialplan, etc. ***
>>   same => n,Return
>>
>>
>>
>> On 12/26/2017 03:28 PM, Dovid Bender wrote:
>>
>> Hi,
>>
>> 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:
>>
>>
>> [outbound]
>> Exten => _X.,1,Dial(SIP/${EXTEN}@1.1.1.1,,U(call-answer-from-carrier))
>>
>> Exten => h,1,NoOp(ANSWERED_TIME: ${ANSWEREDTIME} >>> DIAL_TIME:
>> ${DIALEDTIME} >>> HANGUP_TIME: ${EPOCH} >>> ANSWERED TIME
>> ${MATH(${EPOCH}-${ANSWEREDTIME},int)})
>>
>> [call-answer-from-carrier]
>> Exten => s,1,Noop(CALL WAS ANSWERED AT ${EPOCH}
>> Exten => s,n,Agi(some_script.py)
>>
>> 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 

Re: [asterisk-users] Answered time on channel

2017-12-27 Thread Dovid Bender
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.



On Tue, Dec 26, 2017 at 4:40 PM, Eric Wieling  wrote:

> Don't use an 'h' extension, use a hangup handler.
> 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.
>
> [outbound] ; this is called on the incoming (caller) channel
> exten => _X.,1,Noop
>  same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
>  same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
>  same => n, *** unrelated dialplan, AGIs, etc. ***
>  same => n,Dial(SIP/${EXTEN}@1.1.1.1,,U(answer_handler)b(pre_dial_
> handler^s^1)g
>  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. ***
>
>
> [pre_dial_handler] ; this is called on the outgoing (callee) channel
> exten => s,1,Noop
>  same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})
>  same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Return
>
>
> [answer_handler] ; run on outgoing (callee) channel, but sets
> answer_timestamp in the caller channel
> exten => s,1,Noop
>  same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})
>  same => n,Return
>
>
> [hangup_handler]  ; run on incoming (caller) channel, use to do final post
> call cleanup
> exten => s,1,Noop
>   same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})
>   same => n, ***post call cleanup AGIs, dialplan, etc. ***
>   same => n,Return
>
>
>
> On 12/26/2017 03:28 PM, Dovid Bender wrote:
>
> Hi,
>
> 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:
>
>
> [outbound]
> Exten => _X.,1,Dial(SIP/${EXTEN}@1.1.1.1,,U(call-answer-from-carrier))
>
> Exten => h,1,NoOp(ANSWERED_TIME: ${ANSWEREDTIME} >>> DIAL_TIME:
> ${DIALEDTIME} >>> HANGUP_TIME: ${EPOCH} >>> ANSWERED TIME ${MATH(${EPOCH}-${
> ANSWEREDTIME},int)})
>
> [call-answer-from-carrier]
> Exten => s,1,Noop(CALL WAS ANSWERED AT ${EPOCH}
> Exten => s,n,Agi(some_script.py)
>
> 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.
>
> Any tips on how I can get the same answered time across the board?
>
> TIA.
>
> Dovid
>
>
>
>
>
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Answered time on channel

2017-12-26 Thread Steve Edwards

On Tue, 26 Dec 2017, Eric Wieling wrote:


Don't use an 'h' extension, use a hangup handler.  


Why?

--
Thanks in advance,
-
Steve Edwards   sedwa...@sedwards.com  Voice: +1-760-468-3867 PST
https://www.linkedin.com/in/steve-edwards-4244281-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Answered time on channel

2017-12-26 Thread Eric Wieling

Don't use an 'h' extension, use a hangup handler.
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.


[outbound] ; this is called on the incoming (caller) channel
exten => _X.,1,Noop
 same => n,Set(MASTER_CHANNEL(start_timestamp)=${STRFTIME(,,%s.%3q)})
 same => n,Set(CHANNEL(hangup_handler_push)=hangup_handler,s,1)
 same => n,Set(MASTER_CHANNEL(callid_ingress)=${SIPCALLID})
same => n, *** unrelated dialplan, AGIs, etc. ***
 same => n,Dial(SIP/${EXTEN}@1.1.1.1 
,,U(answer_handler)b(pre_dial_handler^s^1)g
 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. ***



[pre_dial_handler] ; this is called on the outgoing (callee) channel
exten => s,1,Noop
 same => n,Set(MASTER_CHANNEL(callid_egress)=${SIPCALLID})
 same => n,Set(MASTER_CHANNEL(dial_timestamp)=${STRFTIME(,,%s.%3q)})
 same => n,Return


[answer_handler] ; run on outgoing (callee) channel, but sets 
answer_timestamp in the caller channel

exten => s,1,Noop
 same => n,Set(MASTER_CHANNEL(answer_timestamp)=${STRFTIME(,,%s.%3q)})
 same => n,Return


[hangup_handler]  ; run on incoming (caller) channel, use to do final 
post call cleanup

exten => s,1,Noop
same => n,Set(MASTER_CHANNEL(hangup_timestamp)=${STRFTIME(,,%s.%3q)})
  same => n, ***post call cleanup AGIs, dialplan, etc.***
same => n,Return



On 12/26/2017 03:28 PM, Dovid Bender wrote:

Hi,

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:



[outbound]
Exten => _X.,1,Dial(SIP/${EXTEN}@1.1.1.1 
,,U(call-answer-from-carrier))


Exten => h,1,NoOp(ANSWERED_TIME: ${ANSWEREDTIME} >>> DIAL_TIME: 
${DIALEDTIME} >>> HANGUP_TIME: ${EPOCH} >>> ANSWERED TIME 
${MATH(${EPOCH}-${ANSWEREDTIME},int)})


[call-answer-from-carrier]
Exten => s,1,Noop(CALL WAS ANSWERED AT ${EPOCH}
Exten => s,n,Agi(some_script.py)

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.


Any tips on how I can get the same answered time across the board?

TIA.

Dovid





-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Re: [asterisk-users] Answered time on channel

2017-12-26 Thread Dovid Bender
Seems like what I needed was the SHARED function which is working perfectly.



On Tue, Dec 26, 2017 at 3:28 PM, Dovid Bender  wrote:

> Hi,
>
> 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:
>
>
> [outbound]
> Exten => _X.,1,Dial(SIP/${EXTEN}@1.1.1.1,,U(call-answer-from-carrier))
>
> Exten => h,1,NoOp(ANSWERED_TIME: ${ANSWEREDTIME} >>> DIAL_TIME:
> ${DIALEDTIME} >>> HANGUP_TIME: ${EPOCH} >>> ANSWERED TIME ${MATH(${EPOCH}-${
> ANSWEREDTIME},int)})
>
> [call-answer-from-carrier]
> Exten => s,1,Noop(CALL WAS ANSWERED AT ${EPOCH}
> Exten => s,n,Agi(some_script.py)
>
> 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.
>
> Any tips on how I can get the same answered time across the board?
>
> TIA.
>
> Dovid
>
>
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

[asterisk-users] Answered time on channel

2017-12-26 Thread Dovid Bender
Hi,

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:


[outbound]
Exten => _X.,1,Dial(SIP/${EXTEN}@1.1.1.1,,U(call-answer-from-carrier))

Exten => h,1,NoOp(ANSWERED_TIME: ${ANSWEREDTIME} >>> DIAL_TIME:
${DIALEDTIME} >>> HANGUP_TIME: ${EPOCH} >>> ANSWERED TIME
${MATH(${EPOCH}-${ANSWEREDTIME},int)})

[call-answer-from-carrier]
Exten => s,1,Noop(CALL WAS ANSWERED AT ${EPOCH}
Exten => s,n,Agi(some_script.py)

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.

Any tips on how I can get the same answered time across the board?

TIA.

Dovid
-- 
_
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

Check out the new Asterisk community forum at: https://community.asterisk.org/

New to Asterisk? Start here:
  https://wiki.asterisk.org/wiki/display/AST/Getting+Started

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users