Custom Route on Incoming Call

Hi guys,
Two PBXs connected over a trunk and voice mail accounts on one PBX for both systems.

When a call comes in on a trunk to a particular extension, I want the call to go to a specific voice mail depending on the calling party ID.

When call comes in on a trunk to extension 5299 , look at the calling party ID, and route call to * + calling party ID.
E.g. 2517 calls 5299, then call must route to *2517.

How do I achieve this?
Hope it is clear what I want.

Asterisk 11 + FreePBX12.

Ask the FreePBX users:

If FreePBX weren’t in the way, you would just pass ${CALLERID(num)} to the application, but if you really want to force it to a particular extension, you would use Goto(*{$CALLERID(num)},1)

Asterisk doesn’t have a concept of trunks, at least for SIP, but you would put this in the context associated with the the source peer or physical line.

Thank you.
In FreePBX custom extensions are stored in extensions_custom.conf.
And there I can write my custom dialplan without having to worry about FreePBX.

Is that how my entry would look like?
That doesn’t work.

exten => 5230,1,Answer
exten => 5230,n,Goto(*{$CALLERID(num)},1)

This is very simple task. make sure the trunk context value is equal to the one you have created on extensions_custom.conf