Using [macro-dialout-trunk-predial-hook]

Hi all,
i’m using freepbx but i’m a neophyte on asterisk custom dialplan, so i hope someone can help me to understand this requirement. So here my needs:
We are setting up sip trunking from our asterisk pbx to sip provider, my need is to set up two sip trunks, first one to manage standard incoming and outcoming calls, and the other to manage outgoing anonymous calls. My sip provider, gave me the configuration guide to manage anonymous calls, it says: “if the caller identity needs to be hidden, SIP P-Asserted-Identity needs to be added and its value must be the caller number, then the provider will change it from caller number to anonymous”. To achieve this i need to add these lines to [macro-dialout-trunk-predial-hook]:

exten => s,n,GotoIf($[$["${CALLERPRES():0:6}"!=“prohib”] & $["${CALLERID(NUM)}"!=""]]?done)
exten => s,n,GoSubIf($["${CALLERID(NUM)}":“0[0-9]+”]?HeaderAdd(${CALLERID(NUM)}))
exten => s,n,GoSubIf($["${USEROUTCID}":“0[0-9]+”]?HeaderAdd(${USEROUTCID}))
exten => s,n,GoSubIf($["${DB(AMPUSER/${REALCALLERIDNUM}/outboundcid)}":“0[0-
exten => s,n,GoSubIf($["${TRUNKCIDOVERRIDE}":“0[0-9]+”]?HeaderAdd(${TRUNKCIDOVERRIDE}))
exten => s,n,GoSubIf($["${TRUNKOUTCID}":“0[0-9]+”]?HeaderAdd(${TRUNKOUTCID}))
exten => s,n,GoTo(done)
exten => s,n(HeaderAdd),ExecIf($[${EXISTS(${SIPDOMAIN})}]?SipAddHeader(P-Asserted-
exten => s,n(done),MacroExit()

My doubt is how to add this code, i need to have this behaviour only when a specifi trunk is invoked.
An help would be very valued

Hello @mafi81,

I would have done it like this:

  1. Set an outbound route with an “anonymous” as a caller id at the top of your outbound rules.
  2. Add a prefix to this pattern route *(43 for example) and choose your second trunk.

Add these lines to the end of extensions_custom.conf file:

;Call With a Hidden Number
exten => s,1,NoOp(The caller id name is: ${CALLERID(name)})
exten => s,n,NoOp(The caller id number is: ${CALLERID(num)})
exten => s,n,NoOp(The ampuser is: ${AMPUSER})
exten => s,n,NoOp(The real caller id is: ${REALCALLERIDNUM})
exten => s,n,NoOp(The outbound cli is: ${DB(AMPUSER/${REALCALLERIDNUM}/outboundcid)})
exten => s,n,Set(real_cli=${IF($[ "${DB(AMPUSER/${REALCALLERIDNUM}/outboundcid)}" = "" ]?your_main_number:${DB(AMPUSER/${REALCALLERIDNUM}/outboundcid)})})
exten => s,n,GotoIf($[ "${CALLERID(name)}" = "anonymous" | "${CALLERID(name)}" = "Anonymous" ]?pai-custom:continue)
exten => s,n(pai-custom),SipAddHeader(P-Asserted-Identity: "${real_cli}" <sip:${real_cli}@your_pbx_ip_address\;user=phone>)
exten => s,n,SipAddHeader(Privacy: id)
exten => s,n,MacroExit()

Replace the values of your_main_number and your_pbx_ip_address with your main phone number and real ip address and reload the dialplan (in the Linux console):

rasterisk -x'dialplan reload'

Then, test your anonymous route like that: *43 + your phone number.

Thank you,

Daniel Friedman
Trixton LTD.

Hi danielf,

really thanks to your contribution, i really need it. Please correct me if i didn’t understand your solution:

  • i will create an outbound route for anonymous only: under “Dial Patterns that will use this Route” i will fill CallerID field with the extension that need to be anonymous, i will fill “match pattern” field with the celled number\pattern. Both fields need to be matched to go through the anonymous trunk
  • this outbound route always select the “anonymous trunk”

Now my customized asterisk shows this conf files:

  • file extensions.conf includes lines: #include extensions_additional.conf and #include extensions_custom.conf
  • file extensions.conf includes these two lines:
    exten => s,1,MacroExit()

So my question is: Where do i need to add lines you reported? Under extensions_custom.conf or under extensions.conf? in the first case, do i need to delete\comment macro-dialout-trunk-predial-hook under extensions.conf?
Also “your_pbx_ip_address”: i have two interfaces on my asterisk, one is dedicated to the trunk sip provider, “your_pbx_ip_address” would be this?

many thanks

Hello @mafi81,

Here is an example:

You should insert my lines to the end of extensions_custom.conf file. It will overwrite the ones in the extensions.conf file. Never touch the extensions.conf (It is overwritten on each apply in the GUI). Use only the _custom configuration files.

Your your_pbx_ip_address should be the one that your sip provider is recognizing you (the dedicated network interface) .

Thank you,

Daniel Friedman
Trixton LTD.