Wednesday, September 6, 2017

Modify OUTBOUND callerID number in asterisk

Need to modify the Outbound callerID number that is presented to callers, here's a technique.

Test in FreePBX distro 10.13.66-64bit
FreePBX 13.0.192.9

SCENERIO
Call being sent out a trunk and you need to modify CLID of a certain value and prepend or postpend numbers to it.  In the scenerio below, we look for 7 digit numbers and add 555 in front of the numbers.

INSTALLTION
Copy the [macro-outbound-callerid] context from /etc/asterisk/extensions_additional.conf

and paste it into /etc/asterisk/extensions_override_freepbx.conf

Now scroll down to line 7 approximately and you'll see code similar to this:

exten => s,n(normcid),Set(USEROUTCID=${DB(AMPUSER/${AMPUSER}/outboundcid)})
exten => s,n(bypass),Set(EMERGENCY=${DB(DEVICE/${REALCALLERID}/emergency_cid)})

Insert this line between them:
exten => s,n,Gosub(CIDcheck,s,1)

Now scroll to the bottom of the code you've just pasted, and then copy paste the code below between the ============== symbols at the very bottom of the file.

;==========================================
[CIDcheck]

exten => s,1,NoOp(&&&&Checking CLID LENGTH (<7 digits?))

;take the current CLID and save it.  This will be used to tear apart and check syntax
exten => s,n,Set(FOOclid=${CALLERID(all)})
exten => s,n,Set(FOOprepend=506)
exten => s,n,Set(FOOpostpend=)

thi cut gives us the callerID name.  The format in DB looks like "First Last" <XXXxxxx>  The result will be "First Last"
exten => s,n,set(FOOname=${CUT(FOOclid,<,1)})

;this cut gets the callerid number.  It will look like: XXXxxxx>   -missing the first "<" as that was used as delimiter.  we'll put it back later
exten => s,n,set(FOOnumber1=${CUT(FOOclid,<,2)})

;this gets rid of the trailing ">" symbol, leaving us with only XXXxxxx
exten => s,n,set(FOOnumber=${CUT(FOOnumber1,>,1)})

;if the length of the CLIDnumber is equal to whatever value you set after the = sign, then it will look something like this <zzzXXXxxxxWWW>
exten => s,n,ExecIf($[${LEN(${FOOnumber})} = 7]?Set(USEROUTCID=${FOOname}<${FOOprepend}${FOOnumber}${FOOpostpend}>))
exten => s,n,ExecIf($[${LEN(${FOOnumber})} = 7]?NoOp( CLID CHANGED FROM ${FOOclid} to ${USEROUTCID} leng ${FOOnumber1}))
exten => s,n,return


;==========================================

Save your changes

In the asterisk CLI type
core reload

Make a test call.  Your CLID should now be modified.

No comments:

Post a Comment