Asterisk Tips follow me

First of all: Make sure you also look at app_followme as introduced in Asterisk 1.4!

The following example shows how to create a follow me script to allow Asterisk to ring from your desk phone to a cell phone then back to voicemail. If you are not available to answer the cell phone (or choose not to) it will ring back to Asterisk voicemail.

exten => 1234,1,dial(sip/1234,20)
exten => 1234,2,playback(pls-wait-connect-call)
exten => 1234,3,Setvar(NewCaller=${CALLERIDNUM})
exten => 1234,4,SetCIDNum(0${CALLERIDNUM})
exten => 1234,5,dial(${TRUNK}c/9871234321,20,r)
exten => 1234,6,SetCIDNum(${NewCaller})
exten => 1234,7,voicemail2(u1234@default)
exten => 1234,101,voicemail2(b1234@default)
exten => 1234,102,hangup

exten => 1234,1,dial(sip/1234,20)

  • Present the caller with a transfer message to let them know that the system is doing something.
exten => 1234,2,playback(pls-wait-connect-call)

  • Set a new variable with the current caller id information
exten => 1234,3,Setvar(NewCaller=${CALLERIDNUM})

  • Place a 0 before the caller id number to let the called party know that this is coming as a transfer from the desk phone.
exten => 1234,4,SetCIDNum(0${CALLERIDNUM})

  • Dial the cell phone 987-123-4321. Display a ring to the caller until # is pressed on the cell phone.
exten => 1234,5,dial(${TRUNK}c/9871234321,20,r)

  • If the called party chooses to not accept the call change the callerid information back.
exten => 1234,6,SetCIDNum(${NewCaller})

  • Place the caller into voicemail.
exten => 1234,7,voicemail2(u1245@default)

  • If the called party is on the phone just go to voicemail (this may be out of step??).
exten => 1234,101,voicemail2(b1234@default)

exten => 1234,102,hangup

  • The c after the TRUNK command is what causes the connection to wait until the # key is pressed to complete the call.
  • You can use something other than ,r which causes the caller to hear ringing while the call is being placed to the cell phone. Using ,m as an option will play music on hold until someone answers.

NOTE: This functionality does not appear to work with older builds. Tested and working under CVS-HEAD-07/23/04-23:07:00

Contributed by Jeffry Maynard 7/26/2004

An alternative approach is to allow the user to redefine their own number dynamically. This code assumes a few things: 1) that there is something preventing the outside world from getting to 6900 (toll fraud is bad, mmkay?) and 2) that there is somewhere in your dialplan that traps calls to 69XX and passes them there. Your implementation of the [portable-extensions] context will vary to match your system.

The update of 27 April 2006 replaces the previous incarnation of [portable-extensions] with one that does not use Festival to generate the prompts. It also requires the user to have a voicemail box and uses that password to protect the mapping.

exten => _X.,1,SetVar(ARG1=${EXTEN})
exten => _X.,2,NoOp(${TIMESTAMP} call to portable extension ${ARG1} from ${CALLERIDNUM})
exten => _X.,3,DBGet(target=portable/${ARG1})                   ; jumps to +101 if key is not found
; this has to be this way - we can't timeout a goto...
exten => _X.,4,Dial(IAX2/astpbx-fieldrd/${target}@in-iax2,15)  ; phone back into this pbx using IAX2, ring for 15 seconds, then tear down the call so we don't dump into the target's voicemail box
exten => _X.,5,Goto(testvm,1)
exten => _X.,104,Goto(testvm,1)

; Allow users to register and unregister a target for their portable number
exten => 6900,1,Goto(portable-extensions-6900s,s,1)

exten => testvm,1,MailboxExists(${ARG1}@default)                ; Check if the portable number is a valid local mailbox (ignore the unavail/busy prefix)
exten => testvm,2,SetVar(PRI_CAUSE=42)                          ; if not, then return congestion 'cause this isn't a known number
exten => testvm,3,Playtones(congestion)
exten => testvm,4,Wait(5)
exten => testvm,5,Hangup()
exten => testvm,102,Goto(voicemail-routing,u${ARG1},1)          ; if does exist, then transfer to it

exten => s,1,Answer()
exten => s,2,Background(portable-number-ivr/pleaseenternumber)  ; "Please enter your four digit portable extension number."

exten => _69XX,1,MailboxExists(${EXTEN}@default)
exten => _69XX,2,Goto(i,1)
exten => _69XX,102,VMAuthenticate(${EXTEN}|s)
exten => _69XX,103,Set(targetpn=${EXTEN})                       ; Store the target portable number for later use
exten => _69XX,104,Goto(portable-extensions-6900,s,1)

exten => i,1,Playback(portable-number-ivr/invalidnumber)        ; "That's not a valid portable extension number. Please try again."
exten => i,2,Goto(s,1)

exten => _s,1,DBGet(targetrn=portable/${targetpn})              ; Retrieve the target real number from the database
exten => _s,2,SayDigits(${targetpn})                            ;
exten => _s,3,Playback(portable-number-ivr/isforwardedto)       ; " currently forwarded to..."
exten => _s,4,SayDigits(${targetrn})                            ;
exten => _s,5,Background(portable-number-ivr/presstodeactivate) ; "Press 1 to deactivate or 2 to program a new target."

exten => _s,102,Playback(portable-number-ivr/notarget)          ; "This portable extension number is ringing directly to voicemail"
exten => _s,103,Goto(portable-extensions-6900gather,s,1)

exten => 1,1,DBDel(portable/${targetpn})                        ; Erase the target real number from the database
exten => 1,2,Playback(portable-number-ivr/deactivated)          ; "Deactivated. All calls will transfer directly to voicemail.)
exten => 1,3,Playback(goodbye)
exten => 1,4,Hangup()

exten => 2,1,Goto(portable-extensions-6900gather,s,1)

exten => s,1,Background(portable-number-ivr/entertarget)        ; "Enter the number to forward calls to followed by the pound key. Remember to include a leading 9 for external numbers."

exten => _X,1,SetVar(newtarget=${newtarget}${EXTEN})
exten => _X,2,Set(TIMEOUT(response)=5)

exten => _#,1,Goto(portable-extensions-6900commit,s,1)

exten => s,1,Playback(portable-number-ivr/youentered)           ; "You entered..."
exten => s,2,SayDigits(${newtarget})
exten => s,3,Background(portable-number-ivr/presstoaccept)      ; "Press 1 to reenter or 2 to accept."

exten => 1,1,SetVar(newtarget=)
exten => 1,2,Goto(portable-extensions-6900gather,s,1)

exten => 2,1,DBPut(portable/${targetpn}=${newtarget})
exten => 2,2,Playback(portable-number-ivr/programmed)           ; "Target programmed."
exten => 2,3,Playback(goodbye)
exten => 2,4,Hangup()

Contributed by Kris Boutilier (kb1_kanobe) 5/26/2005, Updated 4/27/2006

See also:

Asterisk | Asterisk Configuration | The Dialplan - extensions.conf

Created by: jmaynard, Last modification: Sun 10 of Jun, 2012 (00:20 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+