Mmm… think I have overlooked something…
You want CFU and CFB.
That means you have to set the values of your wanted forward number and check before sending a call to an account if there is a forward on that account.
To set the forward I use:
exten => _21.,1,Answer()
same => n,Set(DB(CFIM/${CALLERID(NUM)})=${EXTEN:4})
same => n,Playback(vm-saved)
same => n,SayDigits(${EXTEN:4})
same => n,Hangup()
The user calls 21forwardnumber. ie 211234567890, the forward number is 1234567890
Then I have a macro:
[macro-callforwarding]
exten => s,1,Set(temp=${DB(CFIM/${ARG1})})
exten => s,n,GotoIf(${temp}?cfi:nocfi)
exten => s,n(cfi),NoOp( CFI Found)
exten => s,n,Dial(SIP/${temp}@trunk)
exten => s,n,Hangup()
exten => s,n(nocfi),NoOp(No CFI found)
And I call the macro before every connection:
exten => _1234,1,Macro(callforwarding,${EXTEN})
same => n,Dial(SIP/1234)
same => n,Hangup()
Think this should help you…
PS. to remove the forward:
exten => _**21,1,Answer()
same => n,Set(Before=${DB_DELETE(CFIM/${CALLERID(num)})})
same => n,Playback(call-fwd-cancelled)
same => n,Hangup()