Last active
July 1, 2019 15:43
-
-
Save lgaetz/2b3d67a30f86a827121b004ec2f3024a to your computer and use it in GitHub Desktop.
lgaetz-el_cid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; FreePBX user dialplan for setting the outgoing Caller ID dynamically on a per-call basis to match | |
; the NANP area code of the destination number | |
; | |
; Latest version: | |
; https://gist.github.com/lgaetz/2b3d67a30f86a827121b004ec2f3024a | |
; | |
; Usage: | |
; Content below goes in /etc/asterisk/extensions_custom.conf | |
; | |
; License: GNU GPL3+ | |
; | |
; Version History | |
; 2019-06-15 First commit by lgaetz | |
; 2019-06-17 Added check for emerg call to bypass | |
; 2019-06-29 Added check for incomming calls forwarded off system to bypass | |
; 2019-07-01 Updated check for incoming call | |
; 2019-07-01 only extract area code fr 10/11 digit numbers | |
[macro-dialout-trunk-predial-hook] | |
exten => s,1,noop(Entering user defined context macro-dialout-trunk-predial-hook in extensions_custom.conf) | |
; exten => s,n,DumpChan ; uncomment for debug | |
; check if this is an emergency call, and if so bypass all customization. Emerg calls must use an outbound route with the | |
; Emergency option toggled | |
exten => s,n,ExecIf($["${EMERGENCYROUTE}"="YES"]?MacroExit) | |
; check if outbound channel started as an incoming call | |
; if call is from an inbound route don't change CID | |
exten => s,n,ExecIf($["${FROM_DID}"!=""]?MacroExit) ; FreePBX < 12+ | |
exten => s,n,ExecIf($["${DIRECTION}"="INBOUND"]?MacroExit) ; FreePBX 12+ | |
; determine the NANP area code of the outbound number | |
; check to ensure we have 10/11 digit number, and take the 3 digits | |
; from the rightmost 10 digits. This works for both 10 and 1+10 digit dialing | |
exten => s,n,noop(Outbound Number: ${OUTNUM}) | |
exten => s,n,ExecIf($[${LEN(${OUTNUM})}=10 || ${LEN(${OUTNUM})}=11]?set(area_code=${OUTNUM:-10:3})) | |
exten => s,n,noop(Area Code: ${area_code}) | |
; check the outbound-el-cid context to see if there is a specified CID matching the area code | |
; if specified area codes exists, use it otherwise generate random CID | |
exten => s,n,GosubIf($[${DIALPLAN_EXISTS(outbound-el-cid,${area_code},1)}]?outbound-el-cid,${area_code},1:outbound-random-cid,s,1) | |
; log outgoing CID and continue | |
exten => s,n,Noop(Call proceeding with Outbound CID: ${CALLERID(number)}) | |
exten => s,n,MacroExit | |
; end context [macro-dialout-trunk-predial-hook] | |
[outbound-el-cid] | |
; Subroutine that accepts exactly 3 digits and matches to a corresponding outbound CID | |
; one line per CID with the format as follows: | |
; exten => aaa,1,Set(CALLERID(number)=bbbbbbbbbb) | |
; where aaa is the 3 digit NANP area code and bbbbbbbbbb is the outbound cid for the call | |
exten => 902,1,Set(CALLERID(number)=9025554444) | |
exten => 920,1,Set(CALLERID(number)=9205553333) | |
; add additional lines as necessary | |
; this final line is required in order to send the call flow back to the calling gosub line | |
exten => _XXX,n,Return | |
; end context [outbound-el-cid] | |
[outbound-random-cid] | |
; this context generates a random number and chooses from a list of fixed outbound caller IDs | |
; based on the random result | |
exten => s,1,noop(Entering user defined context outbound-random-cid in extensions_custom.conf) | |
exten => s,n,Set(foo=${RAND(1,3)}) ;choose a random number between 1 and 3 | |
exten => s,n,Noop(choosing random CID #${foo}) | |
exten => s,n,goto(${foo},1) | |
exten => 1,1,set(CALLERID(number)=5551111111) | |
exten => 2,1,set(CALLERID(number)=5552222222) | |
exten => 3,1,set(CALLERID(number)=5553333333) | |
; add additional lines as necessary | |
; this final line is required in order to send the call flow back to the calling gosub line | |
exten => _X!,n,Return | |
; end contxt [outbound-random-cid] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment