Dialplan strip digit from incoming number

Hi Guys,

For incoming calls i want to strip the 61 and add 0.

Elastix 2.4
Asterisk 1.8.20.0
Linux(i386) 2.6.18

At the moment its working for all calls coming in with 61 but it wont answer calls coming in with “Anonymous” as the calls fail.

Here is the /etc/asterisk/extensions_custom.conf

[custom-strip61]
exten => _X!,1,GotoIf($["${CALLERID(num):0:2}" != “61”]?no61atstart)
exten => _X!,n,set(CALLERID(num)=0${CALLERID(num):2:11})
exten => _X!,n,Goto(from-pstn-toheader,${EXTEN},1)

Here is /etc/asterisk/extensions.conf

[from-trunk] ; just an alias since VoIP shouldn’t be called PSTN
include => custom-strip61
include => from-pstn-toheader
include => from-pstn

[from-pstn]
include => from-pstn-custom ; create this context in extensions_custom.conf to include customizations
include => ext-did
include => ext-did-post-custom
include => from-did-direct ; MODIFICATION (PL) for findmefollow if enabled, should be before ext-local
include => ext-did-catchall ; THIS MUST COME AFTER ext-did

As advised it works fine when calls come in with 61 (this is all calls that are not Anonymous) but fails for Anonymous calls as you can see below:

– Executing [61812345678@from-trunk:1] GotoIf(“SIP/ISPhone-00000005”, “1?no61atstart”) in new stack
== Spawn extension (from-trunk, 61881204872, 1) exited non-zero on ‘SIP/ISPhone-00000005’
– Executing [h@from-trunk:1] Goto(“SIP/ISPhone-00000005”, “from-pstn,61881204872,1”) in new stack
– Goto (from-pstn,61812345678,1)
– Executing [61812345678@from-pstn:1] Set(“SIP/ISPhone-00000005”, “__FROM_DID=61881204872”) in new stack
– Executing [61812345678@from-pstn:2] Gosub(“SIP/ISPhone-00000005”, “app-blacklist-check,s,1”) in new stack
– Executing [s@app-blacklist-check:1] GotoIf(“SIP/ISPhone-00000005”, “0?blacklisted”) in new stack
– Executing [s@app-blacklist-check:2] Set(“SIP/ISPhone-00000005”, “CALLED_BLACKLIST=1”) in new stack
– Executing [s@app-blacklist-check:3] Return(“SIP/ISPhone-00000005”, “”) in new stack
– Executing [61812345678@from-pstn:3] ExecIf(“SIP/ISPhone-00000005”, “0 ?Set(CALLERID(name)=anonymous)”) in new stack
– Executing [61812345678@from-pstn:4] Set(“SIP/ISPhone-00000005”, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
– Executing [61812345678@from-pstn:5] Set(“SIP/ISPhone-00000005”, “CALLERPRES()=allowed_not_screened”) in new stack
– Executing [61812345678@from-pstn:6] Goto(“SIP/ISPhone-00000005”, “from-did-direct,5000,1”) in new stack
– Goto (from-did-direct,5000,1)
– Executing [5000@from-did-direct:1] Macro(“SIP/ISPhone-00000005”, “exten-vm,novm,5000”) in new stack
– Executing [s@macro-exten-vm:1] Macro(“SIP/ISPhone-00000005”, “user-callerid,”) in new stack
– Executing [s@macro-user-callerid:1] Set(“SIP/ISPhone-00000005”, “AMPUSER=anonymous”) in new stack
– Executing [5000@from-did-direct:2] Goto(“SIP/ISPhone-00000005”, “,return,1”) in new stack
– Goto (from-did-direct,return,1)

Any suggestions?

We don’t, in general, know how the FreePBX dialplan works, and therefore in exactly what environment their _custom files operate.

You are not modifying the incoming number, but rather the incoming caller ID number.

The trace indicates that your custom context is not being invoked, which brings us back to the first comment.

I know this is an old post but I had exactly the same problem with one of my voip trunks.
This is the solution I came up with:

In extensions_custom.conf I put this:

[from-trunk-custom]
exten => _X!,1,GotoIf($["${CALLERID(name):0:9}" = “Anonymous”]?anon)
exten => _X!,1,GotoIf($["${CALLERID(num):0:2}" != “61”]?61)
exten => _X!,n,set(CALLERID(num)=0${CALLERID(num):2:11})
exten => _X!,n(anon),Goto(from-trunk,${EXTEN},1)
exten => _X!,n(61),Goto(from-trunk,${EXTEN},1)

And in the peer settings in the trunk “from-trunk-custom”.

Hope this helps someone.