[Asterisk-Users] Call forwarding

The Traveller traveler at xs4all.nl
Wed May 14 12:43:54 MST 2003


Yo,

Inspired by the example in the tips & tricks-section of
"http://www.junghanns.net/asterisk/", I built a more elaborate
call divert-feature.  This one validates if the extension a call-forward
is to be set to is actually valid for the current context and
additionally saves this context into the DB and always uses it to
originate the divert from, as you can't expect the destination
extension to be available from all caller's contexts.  Furthermore,
it supports immediate forward, forward on busy and forward on no answer.

Some things you need to know:

- No check for forwarding-loops yet.  I haven't tried what happens
when you create one, either.  :-)

- When a call gets forwarded to another local extension and goes to
voicemail from there, voicemail will be left for the extension that
originally diverted the call, instead of the extension the call was
diverted to.  This might be seen as a feature.

- The contexts to set the diverts are to be included into the
context of each extension you want to allow to use them and you
should replace your macro-stdexten with my version (which accepts
some more args than the original version, to allow for passing all possible
arguments to the "Dial"-application.  This means you have to change
either your extension-entries or the macro, if you're already using
"macro-stdexten".

- There's currently a bug in Asterisk, related to using app_chanisavail
on chan_local the way I do to check for the validity of the forwarding-
number.  This causes an instance of chan_local to remain lingering
around in the "Ring"-state each time a divert has been set successfully.
These hanging channels seem harmless, apart from cluttering
the system.  The only way to get rid of them, is to force a restart of
Asterisk.  Mark knows about this and will probably fix it as soon as
he has the time for it.



Usage:

921<number>       - Set unconditional divert.
921               - Cancel unconditional divert.
9921              - Check unconditional divert.

961<number>       - Set divert on no answer.
961               - Cancel divert on no answer.
9961              - Check divert on no answer.

967<number>       - Set divert on busy.
967               - Cancel divert on busy.
9967              - Check divert on busy.


Note that I choose "9" instead of "*" because a lot of IP-phones
don't allow the user to send the "*".  Nothing stops you from changing
it as needed.

Also note that this is almost my first go at it, and I haven't tested it
very heavily.  Comments, suggestions and additions are welcome.  Have
fun with it!  :-)




    Grtz,

      Oliver




[macro-stdexten];
;
; Standard extension macro:
;   ${ARG1} - Extension  (we could have used ${MACRO_EXTEN} here as well
;   ${ARG2} - Device(s) to ring
;   ${ARG3} - Timeout
;   ${ARG4} - Other options to app_dial
;
exten => s,1,DBget(fwdexten=CFU/${ARG1})
exten => s,2,DBget(fwdcontext=CFUC/${ARG1})
exten => s,3,Goto(${fwdcontext}|${fwdexten}|1)
exten => s,102,Goto(s|4)
exten => s,4,Dial(${ARG2},${ARG3},${ARG4})
exten => s,5,DBget(fwdexten=CFNA/${ARG1})
exten => s,6,DBget(fwdcontext=CFNAC/${ARG1})
exten => s,7,Goto(${fwdcontext}|${fwdexten}|1)
exten => s,106,Goto(s|8)
exten => s,8,Answer
exten => s,9,Voicemail2(su${ARG1})
exten => s,10,Hangup
exten => s,105,DBget(fwdexten=CFB/${ARG1})
exten => s,106,DBget(fwdcontext=CFBC/${ARG1})
exten => s,107,Goto(${fwdcontext}|${fwdexten}|1)
exten => s,206,Goto(s|108)
exten => s,108,Answer
exten => s,109,Voicemail2(sb${ARG1})
exten => s,110,Hangup


;
; Special features, Call Forwarding, unconditional.
;
[feature-cfu]
exten => _921X.,1,Answer
exten => _921X.,2,ChanIsAvail(Local/${EXTEN:3}@${CONTEXT})
exten => _921X.,3,DBput(CFU/${CALLERIDNUM}=${EXTEN:3})
exten => _921X.,4,DBput(CFUC/${CALLERIDNUM}=${CONTEXT})
exten => _921X.,5,SayDigits,${EXTEN:3}
exten => _921X.,6,Hangup
exten => _921X.,103,Playback(invalid)
exten => _921X.,104,Hangup
exten => 921,1,Answer
exten => 921,2,DBdel(CFU/${CALLERIDNUM})
exten => 921,3,DBdel(CFUC/${CALLERIDNUM})
exten => 921,4,SayDigits,${CALLERIDNUM}
exten => 921,5,Hangup
exten => 9921,1,Answer
exten => 9921,2,DBget(fwdexten=CFU/${CALLERIDNUM})
exten => 9921,3,SayDigits,${fwdexten}
exten => 9921,103,SayDigits,${CALLERIDNUM}
exten => 9921,4,Hangup

;
; Special features, Call Forwarding, on no answer.
;
[feature-cfna]
exten => _961X.,1,Answer
exten => _961X.,2,ChanIsAvail(Local/${EXTEN:3}@${CONTEXT})
exten => _961X.,3,DBput(CFNA/${CALLERIDNUM}=${EXTEN:3})
exten => _961X.,4,DBput(CFNAC/${CALLERIDNUM}=${CONTEXT})
exten => _961X.,5,SayDigits,${EXTEN:3}
exten => _961X.,6,Hangup
exten => _961X.,103,Playback(invalid)
exten => _961X.,104,Hangup
exten => 961,1,Answer
exten => 961,2,DBdel(CFNA/${CALLERIDNUM})
exten => 961,3,DBdel(CFNAC/${CALLERIDNUM})
exten => 961,4,SayDigits,${CALLERIDNUM}
exten => 961,5,Hangup
exten => 9961,1,Answer
exten => 9961,2,DBget(fwdexten=CFNA/${CALLERIDNUM})
exten => 9961,3,SayDigits,${fwdexten}
exten => 9961,103,SayDigits,${CALLERIDNUM}
exten => 9961,4,Hangup

;
; Special features, Call Forwarding, on busy.
;
[feature-cfb]
exten => _967X.,1,Answer
exten => _967X.,2,ChanIsAvail(Local/${EXTEN:3}@${CONTEXT})
exten => _967X.,3,DBput(CFB/${CALLERIDNUM}=${EXTEN:3})
exten => _967X.,4,DBput(CFBC/${CALLERIDNUM}=${CONTEXT})
exten => _967X.,5,SayDigits,${EXTEN:3}
exten => _967X.,6,Hangup
exten => _967X.,103,Playback(invalid)
exten => _967X.,104,Hangup
exten => 967,1,Answer
exten => 967,2,DBdel(CFB/${CALLERIDNUM})
exten => 967,3,DBdel(CFBC/${CALLERIDNUM})
exten => 967,4,SayDigits,${CALLERIDNUM}
exten => 967,5,Hangup
exten => 9967,1,Answer
exten => 9967,2,DBget(fwdexten=CFB/${CALLERIDNUM})
exten => 9967,3,SayDigits,${fwdexten}
exten => 9967,103,SayDigits,${CALLERIDNUM}
exten => 9967,4,Hangup



More information about the asterisk-users mailing list