Can you tell if call forwarded?

Is there a way to see if a call is forwarded from another number then to do something?

Ie if call forwarded from xxx-xxx-xxx1 then send to voicemail box 101

If call forwarded from xxx-xxx-xxx1 then send to voicemail box 102

??

Almost certainly, but your example is faulty. Also, how are using “forwarded” in the original sentence? Are the numbers on your PBX? Are they coming from an outside source? Tell us what you are trying to do within the PBX and we should be able to get you squared away.

The dialplan function CALLERID(RDNIS) should have the value of the forwarding number.

FreePBX does not have a way to analyze that in an inbound route so you will have to write a bit of dialplan to check the value and route the call accordingly.

Forwarded from an outside source. Ie from a cellphone.

A dialplan? Isn’t that used for outgoing?

In FreePBX and Asterisk terms, dialplan is the script that is executed when a call is initiated. FreePBX generates it for you when you set up various components (inbound and outbound routes, IVRs, ring groups, etc) but you can also add your own by editing a set of “custom.conf” files. Most FreePBX admins probably won’t do that, but your case doesn’t seem to be handled by FreePBX and would require the custom configuration.

oohh…can you point me in the right direction to be able to create these custom conf files and enable them?

Actually, I can’t. I was looking for a wiki page describing how it works and can’t find one. Maybe someone else has a good resource.

I can point you to the Asterisk resource on how to write dialplan: https://wiki.asterisk.org/wiki/display/AST/Contexts%2C+Extensions%2C+and+Priorities

Custom dialplan goes in the file /etc/asterisk/extensions_custom.conf

You can jump into it from an incoming call by setting the trunk’s context to your custom context, or by defining a Custom Destination.

This may be the point where you decide whether you want to go this route and become an Asterisk expert, or come up with some other logic for handling your calls that can be done from the FreePBX web interface. :slight_smile:

If I can figure out the custom dialplan, then I don’t need to buy multiple DIDs for our voicemail as we could use one single number…

Assuming that your incoming trunk context is from-trunk, add or put this code into
/etc/asterisk/extensions_custom.conf

[from-trunk-checkdivert]
exten => _X!,1,Noop(RDNIS=${CALLERID(rdnis)})
exten => _X!,n,Goto(from-trunk,${EXTEN},1)

Change the context for the trunk to from-trunk-checkdivert
Apply config and make a test incoming forwarded call. Look at the Asterisk log for a line with something like
RDNIS=2125551212
showing the number that forwarded the call. If RDNIS is null, either the forwarding carrier doesn’t add a Diversion header, or your trunking provider doesn’t send it. If it is present, note the exact format and modify extensions_custom.conf to look like this

[from-trunk-checkdivert]
exten => _X!,1,Noop(RDNIS=${CALLERID(rdnis)})
exten => _X!,n,GotoIf($["${CALLERID(rdnis)}" = "2125551212"]?from-internal,*1234,1)
exten => _X!,n,Goto(from-trunk,${EXTEN},1)

Apply config and make another test call. The forwarded call should now be sent to voicemail for extension 1234.

Once this is working, add a similar GotoIf statement for each number for which you want to handle forwarding.

If you have trouble, post details including country, trunking provider and forwarding carrier.

1 Like

You are amazing sir. Unfortunately my provider does not pass on the
Diversion header… do you know any that do that are affordable?

Oh, will it be bad to keep the context to from-trunk-checkdivert or should I change it back until I find a provider that does pass it on?

At the Asterisk command prompt, type
pjsip set logger on
or
sip set debug on
according to trunk type. Make a test call and look at the incoming INVITE for forwarding info. It may be in a different header or format than what FreePBX expects.

If no luck, in what country is the DID?

Canada. I also confirmed with the provider that they don’t provide this. He opened a ticket to see if they can, but they do not currently.

Take a look at SignalWire. I don’t know whether they support Diversion (and can’t test easily because my mobile plan doesn’t permit international forwarding), but Canada DIDs are only $0.08 per month + $0.00325 per minute (prices in US$). Voicemail calls are usually short so the per-minute charges shouldn’t be too bad. You get a small credit at signup so you can test without making a payment.

AnveoDirect supports Diversion headers on my US and France DIDs, though I can’t be sure about Canada. Metered Canada DIDs are (US) $0.50/mo. + $0.004/min. No registration, so you need a static IP address to receive the calls.

Voxbeam supports Diversion headers on my US and UK DIDs, though I can’t be sure about Canada. They offer Canada DIDs for (US) $1.50/mo. unmetered but see the website for restrictions.

Thanks Stewart! The signalwire documentation is horrendous, but if that pricing is real…that’s crazy! Are they reliable and good quality calls?

I can’t change my outbound CID with them. Did I do something wrong? I connected with PJSIP to them, but when I change my CID on my extension, it doesn’t change. I even changed it to a verified number.

I thought you would be using them only for incoming.

SW does not permit sending a caller ID that is not yours, but verified numbers should be ok. In your trunk, Send RPID/PAI should be Send P-Asserted-Identity header, caller ID should be formatted e.g. +14162223333 and the Caller ID field for the Endpoint on SW portal should be left blank.

Ya I was trying to see if I could move everything for cost efficiency, but it might not be a bad idea to keep a couple providers…

I still need to test the Diversion Headers. Were you able to see if they did pass them?

I can’t get the incoming calls to work. Says that the number is not in service…