Custom dialplan is redirecting all calls to caller id


I’m trying to build a new dialplan to redirect a call to an extension based on the dialed number (DID) but I already stuck at the very beginning.
I’ve created a custom dialplan in the ‘extensions_custom.conf’ and added the following lines;

exten => _X.,1,NoOp(entering dialplan-did-to-extention ${CALLERID(DNID)})
exten => _X.,n(BUSY),hangup

In Freepbx I rerouted the inbound did to a custom application, that has as a target ‘dialplan-did-to-extention,${EXTEN},1’

I was expecting a log entry starting with ‘‘entering dialplan-did-to-extention’’ and ending with the hangup, but instead the call is being redirected to the callerid (I’m dailing with my cell phone, so I end up with my own vm welcome message)]

The log shows:
Goto (dialplan-did-to-extention,##my-did-nr###,1)
– Executing [##my-did-nr###@dialplan-did-to-extention:1] NoOp(“SIP/my-trunk-name-0000073f”, “entering dialplan-did-to-extention ##my-did-nr###”) in new stack
– Executing [##my-did-nr###@dialplan-did-to-extention:2] Hangup(“SIP/my-trunk-name-0000073f”, “”) in new stack
== Spawn extension (dialplan-did-to-extention, ##my-did-nr###, 2) exited non-zero on ‘SIP/my-trunk-name-0000073f’

Can anyone explain why that call is being transfered to my own number?


You’re not using the CallerID but the dialed DID to route the call.

There’s nothing here to check the CallerID and match against it. You would need

exten => _X./_X.,1,NoOp()

What comes after that / is the CallerID so it’s exten/callerid in that format to match against. So if you want it to match against a specific callerid it would be like this:

exten => _X./3135551212,1,NoOp()

^^^ That will match any incoming DID that is being called with the CallerID of 3135551212.

Hi Tom,

exactly, I’m using the DID. That’s what I need!
I’ll explain; when any caller is calling us at 3135551212 , I want to have extention 712 ring.
And when any caller calls 3135551218, ext 718 should ring.

So, I’m trying the first few steps and that get me some results. The issue here is that the external phone that is calling - lets say 31355551212 - is being called back by the pbx…

You’re not understand what I am saying.

exten => _X./3135551212,1,GoTo(from-did-direct,712,1)
exten => _X./3135551218,1,GoTo(from-did-direct,718,1)

So my next question is, why are you using custom contexts for this when the CallerID filed in Inbound Routes does this for you automatically. You would need to add an entry in the Inbound Routes for each DID/CallerID match. You can even use Pattern Matching.

You create the inbound route, DID Number = _X. CallerID Number = 3135551212 and the destination is Extensions => 721. You would then repeat that for the next CallerID Number and set the destination to Extensions => 718.

So that would allow any incoming DID to match and use the CallerID to match against and route the call. There is no need for a custom context for this, it is fully doable in the GUI under Inbound Routes.

1 Like

Hi Tom,

I know I can do that manually, but there are other things:

  • what if I have 100 DID’s
  • the ‘next hop’ when the extension is not aswering should be something different the the normal action (like going to ext voicemal)

The whole idea in Asterisk dial plans is to be able to automate these tasks.

internal calling ext 2XX , just follow ext voicemail when unanswerd.

When externally called DID matches pattern 123456XX then call ext 2XX and if not aswered in 20 seconds call reception and set alert info ‘Direct 2XX’
This behaviour requires some programming in the dialplan (my choice) OR create 100 inbound routes, and 100 RING groups with alert info etcetc (as you are proposing :slight_smile: )

If you’re going to ignore all of the programming that FreePBX can provide, why are we having this discussion here and not in the Asterisk Forum?

If you are trying to write a system that automates this stuff, then you don’t need FreePBX - you need straight Asterisk. Also, it is sounding a little like you are trying to set up a multi-tenant solution using FreePBX, which is really outside the scope of the system. Can you use it for that? Yes. Can you drive a screw with a hammer? Yes. Neither of those answers is optimal.

1 Like

The match of _X. covers that. It matches ANY things that is being sent. You specifically said you wanted to match based on the Caller’s CallerID and route the call based on that. So in order to route based on the Caller’s CallerID you need a MATCH for said CallerID. So the amount of CallerID’s you need to specifically match against is the amount of routes you need to have.

So you basically want to handle External vs Internal differently. That would have been something to mention originally as you now have to write A LOT of dialplan to make this happen. But let’s be clear on something, so far your custom dialplan isn’t cutting for that.

Once you send the call to the extension you now need to customize how that extension is called. Not done at the IVR or Inbound Route level or any other level. When the PBX decides it is going to call extension 785 you need to tell it what to do with that call because that is a new channel. So when that channel doesn’t answer in X amount of times you need to catch that and then redirect it based on the fact the caller is external or internal.

Changing things at the Inbound Route, Ring Group, IVR, Queue or any of those destinations hit before sending it to the extension isn’t going to do crap unless you take the variables you set for that and do something with them when the Dial() completes. Otherwise the system is going to follow the extensions setup and use the Alt. Destinations configured for it.

You also can’t set the Alert Info to “Direct 2XX”. Alert Info changes the ring type to use on the phone a.k.a the Alert. So you’re going to want to set the Alert Info to a ring type different from regular calls and you’re going to want to prefix the CallerID with your “Direct 2xx” so they know where the call is coming from.

uhm, no I wrote DID …
Based on the DID I want to reroute…

The CallerID I was referring is the issue; When I make a call from the cellphone to an incoming number (DID) that is going to use the dialplan as I have for so far (those few lines that shouldn’t do anything) the call is automatically (automagically) rerouted back to my own cellphone (my number of the cellphone is the CalledID.
The CalledID is not in question here all…

OK but that still doesn’t change things. You want to MATCH a specific set of patterns and then route them to a specific location. This is exactly what Inbound Routes does. Doesn’t matter if you’re matching the dialed DID or the CallerID. For each DID you want to match and have a specific and different destination to, you need dialplan for it.

Or you can use you catch all pattern and then look in AstDB or another source and again, match that DID and set the route it needs to use.

The claims it rerouted back out to your cell are not backed by actual proof or evidence of this happening. You showed a piece of the log for the call not the whole call. And even then your piece shows a hangup just like your dialplan said to do.

You need to show this actually happening with a full call debug. Just keep in mind that even when this problem is resolved and the call goes to an extension you want to treat it differently so that code still needs to be put in there somewhere.

Allright, we are not getting anywhere. I didn’t know I needed to present proof of my cellphone being called, I assumed you were going to trust me on my very blue eyes. LOL.
I now know Freepbx is closed software that we should not try to manipulate from the custom files although they are editable from the freepbx gui;-)
N/o worries, I’ll try to find the answer on Asterisk forums and update this one when (or if) I find my answer.

Anyways, muchos gracias for the quick replies and I hope to update this ticket soon.

FreePBX is not closed software. It is the exact opposite of that it’s OSS.

You SSH into the PBX and do the following:

asterisk -rvvvvvvvvvv

Then you make your call, you let it do what you say it is doing and then end the call.
Then you copy all the output from when you entered the Asterisk Console to the end of the call, copy it, paste it at and give us the link. We’ll look and see what is happening.

In reviewing the first post, it’s clear now what happened, but since it was contrary to common sense, and contrary to the log lines posted, all of us missed the actual behavior. The only thing I can think that might explain what you saw is that the inbound call was hung up without actually being answered first, so this situation might cause your provider to do something unexpected. Try inserting an answer and wait before the hangup to see if you get the expected result:

exten => _X.,1,NoOp(entering dialplan-did-to-extention ${CALLERID(DNID)})
exten => _X.,n,Answer()
exten => _X.,n,Wait(5)
exten => _X.,n,hangup

Standard procedure there for FreePBX questions is to send people here.

Hi Lorne,

thanks (again) for helpen me out.
That did the trick, issue was as you said. Bit strange though…
Anyways, I was also mislead by the loags that’s why I was turning to the forum in the first place…I couldn’t find it myself.

Anyways, clad you could help me out, and I hope the other users also benefit by this.

Have a great one!

1 Like

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