Propagating extension h

Hi
For some reason, I’ve had to create a specific context for dialing - When I need to dial, I call this context (via Goto) - And I want the h of the initial context to be called upon hangup, not of this second context
.e.g.

[mycontext]
exten => _X.,1,Noop(....do some stuff...)
same => n,Goto(dial,${EXTEN},1)

exten => h,1,Noop(...do the actual hangup stuff....)

[dial]
exten => _X.,Dial(SIP/provider/${EXTEN})
exten => h,1,Noop(Nothing to do here, need to execute h of calling context)

How can I propagate the hangup to the initial context ? I’ve used the hangup handler, but I get ‘Abnormal ‘Gosub(mycontet,h,1)’ exit. Popping routine return locations.’ - that is just a notice, but I am not keen on seeing ‘Abnormal’ stuff on the CLI, and I thought I had seen a much simpler way to achieve this.

Thanks for the help
J

Hangup handler should work for you or why just dont copy the code of the h extension of my [mycontext] to [dial] context , other way would be add a goto() on the dial context that send you to h extension of my context [mycontext] , I havent test it such mode but it should work also

Pre-dial and hangup handlers are subroutines. They are invoked internally by the Gosub application. You must always Return from them or you get the ‘abnormal stuff’ messages.

[myroutine]
exten = s,1,NoOp(Do stuff in subroutine)
same = n,Return()

[mycontext]
exten = _X.,1,NoOp(My extension handling code)
same = n,Gosub(myroutine,s,1)
same = n,Set(CHANNEL(hangup_handler_push)=myroutine,s,1)
same = n,Dial(PJSIP/101,b(myroutine^s^1))
same = n,Hangup()

It is a best practice to end dialplan extension handling with a Hangup. You could get unexpected behavior because execution can fall off the end of your extension handling code and execute dialplan in the middle of another matching extension.

See
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_Gosub
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_Return
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_Dial
https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers

3 Likes

@rmudgett : thanks, with the Return statement, the notice no longer appears
@ambiorixg12 : thanks as well - the [dial] context is called from different places that do different things upon hangup.

Funny, I was convinced I’d seen somewhere a trick to trigger the h of the original context - I must be mistaken !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.