[asterisk-users] Hangup hook to put back a call into a queue

Joshua C. Colp jcolp at sangoma.com
Wed Feb 5 11:31:25 CST 2020

On Wed, Feb 5, 2020 at 12:34 PM Farkas Levente <lfarkas at lfarkas.org> wrote:

> hi,
> I hope someone can help me:-)
> we’ve got a freepbx server. there are 2 special extensions (2001, 2002).
> if someone calls this extensions (or a call is forwarded to these
> extensions) and these extension hangup (not the caller party), then we’d
> like to put the calls back into a queue (1000) and wouldn’t like to hangup.
> I read your description about hangup hooks:
> https://community.freepbx.org/t/hooking-for-fun-and-income/57718
> but still not able to implement it:-(
> what I’ve done:
> * found out in a hard way how to detect the current destination
> extension (because it’s turn out that CALLERID(dnid) is not working in
> case of forwarded call it’s show the original destination)
> * write a macro-dialout-one-predial-hook and a hook marco like this:
> [macro-dialout-one-predial-hook]
> exten => s,1,Noop(Entering user defined context
> macro-dialout-one-predial-hook in extensions_custom.conf)
> exten => s,n,GotoIf($["${DEXTEN}"=“2001”]?special)
> exten => s,n,GotoIf($["${DEXTEN}"=“2002”]?special)
> exten => s,n,MacroExit
> exten => s,n(special),NoOp(--------------- Push Special Hangup Handler
> ------------------)
> exten => s,n,Set(CHANNEL(hangup_handler_push)=back-to-1000-hangup,s,1)
> exten => s,n,MacroExit
> [back-to-1000-hangup]
> exten => s,1,Noop(====== Entering user defined context
> back-to-1000-hangup =======)
> exten => s,n,Queue(1000)
> exten => s,n,Return
> it seems to be called and seem to enter into to call but immediately
> hangup.
> first of all, in this case when in the hangup handler I will NOT like to
> hangup how should I finish the marco?:

Hangup handlers don't allow you any control over the hangup process. You
can't stop it from occurring and in fact when it occurs the channel is
already hung up. Anything that expects a live channel won't work.

> Hangup
> Return
> MacroExit
> how to redirect the call to the queue?:
> Queue(1000)
> ChannelRedirect(${CHANNEL},,1000,1)
> Gosub(ext-intercom,*801000,1())
> dial-one,HhTtrM(auto-blkvm),1000
> and what is the reason I can’t put the call back to the queue?
> I know that I'm already in the hangup sequence, but still wouldn't like
> to hangup.
> or this can't be done in the hangup handler?

You can't do it from a hangup handler. The Dial option provides the g
option[1] which can be used to continue dialplan execution when the called
party hangs up, but I don't work on FreePBX so I can't comment on how best
to use it there.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Dial

Joshua C. Colp
Asterisk Technical Lead
Sangoma Technologies
Check us out at www.sangoma.com and www.asterisk.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20200205/75fa288c/attachment.html>

More information about the asterisk-users mailing list