Alter dialplan for incoming calls

I’ve been using FreePBX (PBX Firmware:10.13.66-17) for a couple of months and I can say that I’m really satisfied. Recently I made some new settings on how the calls will be routed in case that I don’t answer my sip extensions.

So if a call is coming from my DID to my extension (lets say 201) I will see the Caller ID correctly. If I don’t answer, the call will be forwarded to my cellphone but it will have an invalid number because the country code is stripped of by my DID provider. I asked them to alter my account setting on that but that was not an option.

What I need is a dialplan that will detect when an incoming number starts with 2X or 69X and add my country prefix (30) without the plus sign. I didn’t find something that worked in my case.

Have you looked at the Set Caller ID module to see if you can support this through that? I’m pretty sure it’s as simple as that. You may need to create a special Custom Destination for your cell phone so the SetCID module has a destination it can hit.

Thank you for your reply, I really hope someone can help me with this.

Yes I am familiar with the Set Caller ID module but I don’t think that I can accomplish what I need through there.

For now I am using it but it doesn’t work correctly in most cases. The reason is that I created a CID rule and added 30${CALLERID(num)} at the CallerID number field. The destination is set accordingly (to a ring group or my extension) but in that case the prefix (30) is always added. I need that only in case that it doesn’t exist an only if the incoming number start’s with 69x or 2x.

So let’s assume that I get an international call that passes through. I will get a number like +44012345679 and the module will rewrite that to 30+44012345679 which is of course wrong.

Any ideas?

You may need to create a custom context to handle this variability of your requirement. There are lots of examples out there (in fact, on this forum) where people are modifying the Caller ID.

There’s an inbound route that does a lot of this for the inbound number - you can probably start with that and work your way forward from there.

Yes, that’s excaclty what I was trying to do.

I’m not really sure though if the custom context is written right because I can’t get it to work.
That’s an example of the many contexts that I tried.

[custom30]
exten => _69X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => _2X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => _X.,1,Set(CALLERID(number)=${CALLERID(number):1})
exten => ,n,Goto(from-trunk,${EXTEN},1)

OK, so there are lots of other things that need to be working for this to be correct, including the working name for the context. For example, instead of custom30, it should be something like “from-trunk-custom” so that it actually gets included in your context stream.

On to the lines - this is straight Asterisk Context stuff. There’s a book out there called “Asterisk for Dummies” (as well as thousands of examples on the Internet) that talks about the construction of the context.

If I’m reading this right, for any DID with a 69 followed by a 1-9 in it, the caller ID is supposed to be set to the string ‘30’ plus the current caller id number (starting at digit 1).

Also, I don’t think your Set() function is built correctly - I don’t think any of them are actually going to do anything.

If it was me, I’d start with something more like this. It won’t work, but something like this:

[from-trunk-custom]
`exten=>s,1,NoOp(Entering Custom Code for ${CALLERID(number)})`
`exten=>s,n,If($CALLERID(number):1:2='60' ... etc.`

Use ‘If()’ functions to decide if you want to modify the Caller ID, and then, at the end, only add the code it you haven’t “Returned” to the from-trunk context.

There are guys on here that love to write this kind of stuff. Maybe you’ll get lucky and one of them will hack something together quick.

Thanks for your reply. I will try to use the dia plan that you provided and modify that.

In the meantime I will wait for more comments on this.

Almost there, use the

[from-pstn-e164-us]

Context in extensions.conf as a template and send your inbound calls there.

1 Like

Thank you for your reply, yes I saw that context but it confused me. That’s why I tried to create a new one.

Each pattern is massaged as appropriate then sent to from-trunk, the s extension is selected if the number doesn’t match anything else,

I think that I changed that to my needs. There must be an error in the syntax because in the logs i can see:
2017-12-19 17:48:41] NOTICE[27891][C-000007c8] chan_sip.c: Call from ‘6090’ (XXX.XXX.XXX.XXX:5060) to extension ‘6090’ rejected because extension not found in context ‘from-pstn-custom’.

and the call gets terminated.
[from-pstn-custom]
exten => _30XXXXXXXXXX/_30XXXXXXXXXX,1,Set(CALLERID(number)=${CALLERID(number):2})
exten => _30XXXXXXXXXX/_30XXXXXXXXXX,2,Goto(from-pstn,${EXTEN:2},1)
exten => _69X./_69X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => _69X./_3069X.,n,Goto(from-pstn,${EXTEN},1)
exten => _2X./_2X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => _2X./_302X.,n,Goto(from-pstn,${EXTEN},1)
exten => s/_30XXXXXXXXXX,1,Set(CALLERID(number)=${CALLERID(number):2})
exten => s/_30XXXXXXXXXX,n,Goto(from-pstn,${EXTEN},1)
exten => s/_69X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => s/_3069X.,n,Goto(from-pstn,${EXTEN},1)
exten => s/_2X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => s/_302X.,n,Goto(from-pstn,${EXTEN},1)
exten => s,1,Goto(from-pstn,${EXTEN},1)

You don’t need the post / 'qualifier’s for the extensions in your context, remove them all.

I think that is what you mean:

exten => _30XXXXXXXXXX,1,Set(CALLERID(number)=${CALLERID(number):2})
exten => _30XXXXXXXXXX,2,Goto(from-pstn,${EXTEN:2},1)
exten => _69X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => _3069X.,n,Goto(from-pstn,${EXTEN},1)
exten => _2X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => _302X.,n,Goto(from-pstn,${EXTEN},1)
exten => s/_30XXXXXXXXXX,1,Set(CALLERID(number)=${CALLERID(number):2})
exten => s/_30XXXXXXXXXX,n,Goto(from-pstn,${EXTEN},1)
exten => s/_69X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => s/_3069X.,n,Goto(from-pstn,${EXTEN},1)
exten => s/_2X.,1,Set(CALLERID(number)=30${CALLERID(number):1})
exten => s/_302X.,n,Goto(from-pstn,${EXTEN},1)
exten => s,1,Goto(from-pstn,${EXTEN},1)

But I still get the same error. The “6090” is the username of my DID that comes from my provider.
[2017-12-19 18:01:55] NOTICE[27891][C-000007d1] chan_sip.c: Call from ‘6090’ (XXX.XXX.XXX.XXX) to extension ‘6090’ rejected because extension not found in context ‘from-pstn-custom’.

DO NOT USE the from-pstn-custom context. Create new context like from-pstn-georgedal and then change the context for your trunk to match.

Thank you for your comment. I was adviced to change that to "from-trunk-custom” and as I read at the extensions.conf the pstn and trunk are actually the same.

; from-trunk:
;
; Context is really just an aliax of from-pstn
;
[from-trunk]
include => from-pstn.

What about the dialplan? I still get the same error about my DID not found on the context.

I thought I suggested you eliminate ALL the /‘qualifiers’ they won’t help your filter. then look at your s extension , you only need the last one

Please bare with me cause I’m new to this and trying to keep up with all the information. I thought that the /qualifiers that you said were the first part

30XXXXXXXXXX

from the:

exten =>30xxxxxxxxxx/ _30XXXXXXXXXX,1,Set(CALLERID(number)=${CALLERID(number):2}).

Yes, I did remove that. I will remove also the “s” except from the last one.

the bit before the / is your DID that after , the CID , you need to “normalize” your inbound calls so they arrive at the destination looking like what that extension needs to dial the caller back. Thusly the CID is immaterial here.

Then your outbound routes and trunks need to format what your users dial to a format acceptable to your VSPs

I think that I should try a simple dialplan and then change it bit by bit.

So, I create a custom context on extensions_custom.conf. I name it as [from-pstn-georgedal] and add the following

exten => _X.,1,Set(CALLERID(num)=30${CALLERID(num)})
exten => _X.,n,Goto(from-trunk,${EXTEN})

I click on save and apply changes. Next I go to the trunk (named 6090 from the DID) and change the context=from-trunk to context=from-pstn-georgedal, again click on save and apply changes.

This is a dial plan that it is supposed to simply add the prefix 30 on all calls coming though this trunk. I found it from many users by searching on google.

When I call my DID from my cellphone I get the following at the logs

Executing [[email protected]:1] Set(“SIP/did_number-0000000a”, “CALLERID(num)=30here is my cellphone number”) in new stack
– Executing [[email protected]:2] Goto(“SIP/did_number-0000000a”, “from-trunk,6090”) in new stack
– Goto (from-pstn-georgedal,from-trunk,6090)
[2017-12-20 01:53:24] WARNING[32324][C-00000012]: pbx.c:4416 __ast_pbx_run: Channel ‘SIP/did_number-0000000a’ sent to invalid extension but no invalid handler: context,exten,priority=from-pstn-georgedal,from-trunk,6090

I think that by doing these it should work but it doesn’t

Also I’m not sure if the syntax for my version should be ${CALLERID(number) or ${CALLERID(num)

Do you have an inbound route setup for 6090 ?