This script looks for the (channel)/(extension) match from the database.For an extension 100 using SIP and a followme number of 123-456-7890database put 100 LOCAL SIP/100database put 100 FOLLOW 1234567890${TRUNKLD} needs to be set to whatever your outgoing LD provider is[macro-stdexten]; exten => <ext>,<pri>,Macro(stdexten,<number>,<CID>)exten => s,1,SetCallerID(${ARG2}) ; set CallerID Name and Numberexten => s,2,DBGet(EXT=${ARG1}/LOCAL) ; retreive local channel/extensionexten => s,3,NoOp(Local channel/extension for this call: ${EXT}) ; output the value from the databaseexten => s,4,DBGet(FOLLOW=${ARG1}/FOLLOW) ; retreive follow me number (possibly null)exten => s,5,NoOp(Follow me number (possibly NULL): ${FOLLOW}) ; see what the follow me number isexten => s,6,Dial(${EXT},15,t) ; attempt to call the channel/extensionexten => s,7,GotoIf($[${DIALSTATUS} = BUSY]?s-BUSY) ; if busy, just go straight to voicemail ; (don't bother us, we're busy)exten => s,8,GotoIf($[foo${FOLLOW} = foo]?s-${DIALSTATUS}|1:followme|s|1) ; If ${FOLLOW} is NULL, Goto s-${DIALSTATUS} ; else Goto followme,s,1 (because we have a number ; that we can try before going to voicemail)exten => s-NOANSWER,1,Voicemail(u${ARG1}) ; if no answer, play voicemail unavail of extensionexten => s-BUSY,1,Voicemail(b${ARG1}) ; if busy, play voicemail busy of extension[followme]; used from the stdexten macro for follow me service.exten => s,1,ResponseTimeout(${DEFAULT_TIMEOUT}) ; response timeout of (DEFAULT) secondsexten => s,2,Wait(1) ; wait 1 secondexten => s,3,Cut(EXT=EXT,/,2) ; Cut the EXT variable so that we just get the extension numberexten => s,4,Background(hacklocalhost-vm-or-cell) ; *** Custom prompt *** "Press 1 for voicemail or 2 to try that ; this persons follow me line" (or something like that)exten => 1,1,Voicemail(u${EXT}) ; extension number as set in macro-stdextenexten => 2,1,Wait(1) ; wait 1 secondexten => 2,2,Playback(pls-hold-while-try) ; please hold while we try that extensionexten => 2,3,Dial(${TRUNKLD}/1${FOLLOW},15,t) ; call user via our LD trunk to our follow me numberexten => 2,4,Voicemail(u${EXT})exten => h,1,Hangup ; if user hangs upexten => t,1,Playback(goodbye) ; if we reach response timeoutexten => t,2,Hangup ; hangup the lineI call the macro like this:exten => _XXX,1,Macro(stdexten,100,${CALLERID})