Stripping +1 from dial string sent from end point

I have a rather interesting scenario that I would like some advice on. I have a FreePBX Distro 10.13 installation with FreePBX version 13.0. To this, I am integrating two door phones with integrated directories. The way it will work is a person at the door can select a tennent from the directory and the door phone will dial whatever number is programmed in for that directory entry.

The problem is this: no matter what number is given to the directory to dial, it will always prepend “+1” to the dial string, and there is no option to make it not do that. This means that the phone system will need to strip the “+1” from the dial string for just these two extensions prior to it being processed by the rest of the dial plan. This way I can enter either an internal extension or an external number into the directory, and the phone system can figure out the rest.

I am fairly familiar with manually creating a modifying Asterisk dial plans, but I am not familiar enough with how includes interact when dealing with ‘s’ extensions. Any pointers?

In extension.conf, there’s a context that already does this. IIRC. it’s something-E164-something and you can use it as the context for your door phone extensions. It should be able to hit any phone in the local PBX.

Thank you for the follow up.

I see the [from-pstn-e164-us] context, but from reading through it, it looks like would make the calls from the door phones appear to come from an external trunk, so unfortunately I don’t think it would work. After stripping the +1, it sends the call to the [from-pstn] context, which, as far as I know, can’t directly dial an extension or ring group, nor could it dial an outside number.

Edit: However, a custom context that strips the +1, then jumps to [from-internal] dial plan would work, I think. I forgot about custom contexts for extensions. Thanks!

Then write one of your own based on that, and implement that in the extensions_custom.conf file.

The only thing that the [from-pstn] context does is prevent you from calling out on your outbound routes. With that context, you would be able to call any number local to the PBX.

Something like this for 3 digit extensions:

[from-internal-custom]
exten => _+1XXX,1,Noop(Entering user defined context from-internal-custom in extensions_custom.conf)
exten => _+1XXX,n,Goto(from-internal,${EXTEN:-3},1)

sw;dt - should work; didn’t test

1 Like

Thanks, Igaetz, that makes sense. If I understand it right, it will strip the +1 whenever someone dials +1 before an extension, but leave the +1 in place if they dial anything else. Since that will be handled by the dial rules on the trunk, that should work. I had fixated on stripping the +1 from everything, but it doesn’t look like I will need to.

I was worried that if I tried to do something in [from-internal-custom] I would either end up with weird loops or break call flow, since I had read about weird jumps in code if there are overlapping extensions inside includes.

I’ll post back after I have a chance to test.

For anyone who might need this later: Igaetz’s code worked perfectly. Internal and external calls from desk phones process as normal, and calls from the door phones are now working for both calls routed internally and externally. The only things I added were a few dialing rules in my outbound routes to strip the +1 there for external calls (e.g. “+1|1NXXNXXXXXX”).

Thanks for the help!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.