Call Forwarding Help

Hello

Not sure if this is the correct forum, if not, please move

I have the below script that I use for immediate call forwarding. I also use A2billing with CallerID authentication for outgoing calls. A issue has just arisen where someone has forwarded their phone to an outside number. The call fails at the A2billing stage due to a CallerID that is not in the table. I have worked round this by adding a route that looks for numbers starting with 77 to bypass A2billing.

My question is - Is it possible to modify the below code so if someone enters an external number (beginning with 9) that it automatically adds 77 to the beginning. However if they enter a 4 digit internal number which in my case can begin with 3, 4, 5 or 7 then it does not add the leading 77. The leading 77 would only be added if the number they enter begins with 9

eg - if they enter 90536849564 the system saves it as 7790536849564

[custom-cf-on]
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Playback(call-fwd-unconditional)
exten => s,n(startread),Playback(ent-target-attendant)
exten => s,n,Read(toext,then-press-hash,)
exten => s,n,GotoIf($[“foo${toext}”=“foo”]?startread)
exten => s,n,Wait(1)
exten => s,n,Set(DB(CF/${AMPUSER})=${toext})
exten => s,n,Playback(call-fwd-unconditional)
exten => s,n,Playback(is-set-to)
exten => s,n,SayDigits(${toext})
exten => s,n,Macro(hangupcall,)

Thanks

Yes its possible extratc the firs number of the Dialed number then compare using your GotoIf app if its 9 jump to another label and append the 77 to the var if not jump to another label to store the var as the user entered.

If you have doubts check the book www.asteriskdocs.org

Many thanks for the help

I’ve spent a fair bit of time on this but can’t get it to work. I have since realised that you can’t have wildcard matching within a gotoif statement?

Can anyone give me any clues?

Read the documentation on expressions (under channel variables), particularly the bit on regular expressions. If you can’t find it elsewhere, this used to be in doc/tex/channelvariables.tex up to version 1.6.

I have read all of that but still don’t understand how to get it to look at the first entered digit only. It always seems to take the entered number as a whole number.

example - with the below code if i enter an internal number of 7898 that works fine. If i enter an external number 9748576738 that applies but if i enter just 9 it applies 779

exten => s,1,Answer
exten => s,n,Playback(call-fwd-unconditional)
exten => s,n(startread),Playback(ent-target-attendant)
exten => s,n,Read(toext,then-press-hash,)
exten => s,n,GotoIf($[${toext} = 9]?external:internal)
exten => s,n(internal),Set(DB(CF/${AMPUSER})=${toext})
exten => s,n,Macro(hangupcall,)
exten => s,n(external),Set(DB(CF/${AMPUSER})=77${toext})
exten => s,n,Macro(hangupcall,)

Read it again. You don’t even need regular expressions. Look particularly at the use of “:”.