How to do dynamic outbound CID

I have 2 providers both in AU and each provider uses a different format for outbound CID. One wants
then other wants
Yes, the quotes are wanted by one and not the other.

I cant find any way of intercepting the php scripts due to the peculiarities of how the scripts are interpreted.

If anyone has any suggestions, or can point me to some good complete documentation on writing freepbx modules I could have a shot myself.


Have you looked at setting the caller ID on the outgoing trunk? Since trunks are one-for-one to the provider, it would seem to be the simplest way of doing it.

If you need a programmatic solution (say, you’re setting the caller ID based on something in your database), you will probably need to do some text manipulation on the outbound trunk selector context.

Hi Dave,

I had thought about that but I want to be able to have a different CID for each user.

I ended up writing a script to do the work. Not very complex but it took me a while to find all the functions in asterisk as I dont code in it much.

Below is my solution in extensions_custom.conf


exten => s,1,noop(================ OUTROUTE-CUSTOM ====================)

exten => s,n,Set(KTrunk=${CUT(custom,/,2)})
exten => s,n,noop(=== KTRUNK = ${KTrunk} ===)

exten => s,n,NoOp(CUSTOM: calleridall is ${CALLERID(all)})
exten => s,n,NoOp(CUSTOM: calleridnumber is ${CALLERID(number)})
exten => s,n,Set(KCID=${CALLERID(number)})

exten => s,n,GotoIf($["${KTrunk}" = "Nehos"]?Nehos)
exten => s,n,GotoIf($["${KTrunk}" = "DidLogic"]?DidLogic)
exten => s,n,MacroExit

exten => s,n(Nehos),noop(== NEHOS ==)
exten => s,n,noop(== ${KCID} == 0${KCID:2} ===)
exten => s,n,Set(CALLERID(name)=0${KCID:2})
exten => s,n,MacroExit

exten => s,n(DidLogic),noop(== DIDLOGIC ==)
exten => s,n,MacroExit

It lets me do what I wanted and can grow if needed. Now all I need to do is put the CID I want into the extension with no quotes or brackets in 61812345678 form and the script will fix it for the selected provider. The names are just the trunk names I have in freepbx.


1 Like