[asterisk-users] How to execute priorities following a caller hangup in a successful Dial?

Eric Wieling ewieling at nyigc.com
Tue Jun 5 14:58:46 CDT 2018


Don't use the _. pattern.  Ever.

The call has two channels so it needs two hangup handlers, something 
like this, though I've not tested it.

[some_context]
exten => _X.,1,Noop
  same => n,Set(CHANNEL(hangup_handler_push)=my_caller_hangup_handler)
  same => n,Dial(SIP/number at peer,b(pre_dial^s^1))
  same => n,Hangup

[pre_dial]
exten => s,1,Set(CHANNEL(hangup_handler_push)=my_called_hangup_handler)
  same => Return

See: https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers
and https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers


On 06/05/2018 03:37 PM, David P wrote:
> Thanks, Eric. I just tried a hangup handler, but it's showing a similar 
> problem: When the peer hangs-up, the hangup handler is not invoked and 
> the caller channel remains open.
> 
>   same => 
> n(callPeer),Set(GLOBAL(Peer${IndexIntoPeers}CurrentCallsCount)=$[${PeerCurrentCallsCount} 
> + 1])
>   same => 
> n,Set(CHANNEL(hangup_handler_push)=handleHangupByCallerOrPeer,doesntMatter,1(args))
>   same => n,Set(DialForPeer=SIP/${EXTEN:0:4}@${PeerBeingConsidered})
>   same => n,Dial(${DialForPeer})
>   same => n,Hangup()
> [handleHangupByCallerOrPeer]
> exten => _.,1,NoOp(${PeerBeingConsidered}: Entered 
> handleHangupByCallerOrPeer Calls ${Peer${IndexIntoPeers}CurrentCallsCount})
>   same => 
> n,Set(GLOBAL(Peer${IndexIntoPeers}CurrentCallsCount)=$[${Peer${IndexIntoPeers}CurrentCallsCount} 
> - 1])
>   same => n,Set(GLOBAL(${PeerBeingConsidered}EpochAtCallEnd)=${EPOCH})
>   same => n,Return()
> 
> I've also tried replacing the Dial above with:
> 
>   same => n,Dial(${DialForPeer},,g)
> 
> Cheers,
> David
> 
> On Tue, Jun 5, 2018 at 7:38 AM, Eric Wieling <ewieling at nyigc.com 
> <mailto:ewieling at nyigc.com>> wrote:
> 
>     Use hangup handlers, they work around the issues with the 'h' extension.
> 
>     On 06/05/2018 05:33 AM, David P wrote:
> 
>         Thanks, Anthony.
> 
>         I added both 'g' and 'F' options. Now, when the caller hangs-up,
>         my cleanup code is run by both the caller channel and the peer
>         channel, but I only want the caller channel to do that.
> 
>         Also, when the peer hangs-up, there is no execution of the
>         priorities following the Dial.
> 
>         Finally, is there a way to reset all globals, maybe as a variant
>         of "dialplan reload"?
> 
>         On Tue, Jun 5, 2018 at 1:21 AM, Antony Stone
>         <Antony.Stone at asterisk.open.source.it
>         <mailto:Antony.Stone at asterisk.open.source.it>
>         <mailto:Antony.Stone at asterisk.open.source.it
>         <mailto:Antony.Stone at asterisk.open.source.it>>> wrote:
> 
>              On Tuesday 05 June 2018 at 08:33:26, David P wrote:
> 
>              > We're using Asterisk 14.7.6 and I have a dialplan that
>         ends like this:
>              >     >  same => n,Dial(SIP/${EXTEN:0:4}@peer1)
>              >  same => n,Set(GLOBAL(EpochAtCallEnd)=${EPOCH})
>              >  same => n,Hangup()
>              >     > When peer1 hangsup, the priorities after the Dial
>         are executed fine. But
>              > when the caller hangsup during the Dial, the cleanup
>         steps aren't done.
>              > Why?
>              >     > I did read "Note that on a successful connection,
>         in the absence of the g
>              > and G modifiers (below), the Dial command does not return
>         to allow
>              > execution of further commands for that extension in that
>         context." at
>              > https://www.voip-info.org/asterisk-cmd-dial/
>         <https://www.voip-info.org/asterisk-cmd-dial/>
>              <https://www.voip-info.org/asterisk-cmd-dial/
>         <https://www.voip-info.org/asterisk-cmd-dial/>> But it seems not
>         to apply
>              > because I'm seeing the 'g' behavior without specifying
>         that option, and the
>              > 'G' option seems intended for a far more complicated
>         scenario.
> 
>              If you're getting "g" functionality without specifying it,
>              congratulations.
> 
>              If you want something similar when the callER hangs up, you
>         want to
>              use the F
>              option.
> 
>              Regards,
> 
> 
>              Antony.
> 
> 
> 
> 
>     -- 
>     http://help.nyigc.net/
> 
> 
> 
> 

-- 
http://help.nyigc.net/



More information about the asterisk-users mailing list