Set random CallerID from the list

hello,

I’m new in writing dialplan and I need help with adding a feature to set random outbound CallerID from the list for serveral extensions

I found the code below, which is belongs @lgaetz, it is working perfect but for all outbounds:

[macro-dialout-trunk-predial-hook]
exten => s,1,noop(Entering context ${CONTEXT} defined 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)=1111111111)
exten => 2,1,set(CALLERID(number)=2222222222)
exten => 3,1,set(CALLERID(number)=3333333333)

how to apply for specific trunk and extensions ?

thank you

I’m composed this:

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(Entering user defined context macro-dialout-trunk-predial-hook in extensions_custom.conf)
 same => n,ExecIf($["${OUT_${DIAL_TRUNK}_SUFFIX}"!="@trunk_name"]?MacroExit())
 same => n,ExecIf($["${AMPUSER}"!="100"&"${AMPUSER}"!="101""${AMPUSER}"!="102"&"${AMPUSER}"!="103"]?MacroExit())

 same => n,NoOp(choosing random CID ${CALLERID(num)})
 same => n,Set(rand=${RAND(1,3)})
 same => n,NoOp(choosing random CID ${rand} ${CALLERID(num)})
 same => n,GoTo(${rand},1)

exten => 1,1,Set(CALLERID(num)=11111111)
exten => 2,1,Set(CALLERID(num)=22222222)
exten => 3,1,Set(CALLERID(num)=33333333)

it’s work for me, but I want to optimise and simplify
I can’t send ExecIf($["${AMPUSER} to separate context (it did’nt working)
need your adviсe or direction to understand the logic

thank you

currently working code on testing now
thanks to void … and @lgaetz and ChatGPT for the samples i was inspired by

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(Entering user defined context macro-dialout-trunk-predial-hook in extensions_custom.conf)
include => randomCID
exten => s,,MacroExit()
 
[randomCID]
;Set random CID if conditions match
exten => s,1,NoOp(Entering user defined context randomCID in extensions_custom.conf)
 same => n,ExecIf($["${OUT_${DIAL_TRUNK}_SUFFIX}"!="@trunkname"]?MacroExit())
 same => n,GotoIf($[${REGEX("^([1-3][0-9][0-9])$" ${AMPUSER})}=1]?label1,1)

exten => label1,1,Set(CIDs=111111,222222,333333)
 same => n,Set(rand=${RAND(1,3)})
 same => n,Set(CALLERID(num)=${CUT(CIDs,\,,${rand})})

updated

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(Entering user defined context macro-dialout-trunk-predial-hook in extensions_custom.conf)
 same => n,GoSub(randomCID,s,1)
exten => s,n,MacroExit()
 
[randomCID]
exten => s,1,NoOp(Entering user defined context randomCID in extensions_custom.conf)
 same => n,ExecIf($["${OUT_${DIAL_TRUNK}_SUFFIX}"!="@trunkname"]?Return())
 
 same => n,GotoIf($[${REGEX("^(1[0-9][0-9])$" ${AMPUSER})}=1]?co100,1)
 same => n,GotoIf($[${REGEX("^(2[0-9][0-9])$" ${AMPUSER})}=1]?co200,1)
 same => n,GotoIf($[${REGEX("^(3[0-9][0-9])$" ${AMPUSER})}=1]?co300,1)

exten => s,n,Return()

exten => co100,1,Set(CIDs=111111111,222222222,333333333)
 same => n,Set(rand=${RAND(1,3)})
 same => n,Set(CALLERID(num)=${CUT(CIDs,\,,${rand})})
 same => n,Goto(end,1)

exten => co200,1,Set(CIDs=444444444,555555555,666666666)
 same => n,Set(rand=${RAND(1,3)})
 same => n,Set(CALLERID(num)=${CUT(CIDs,\,,${rand})})
 same => n,Goto(end,1)
 
exten => co300,1,Set(CIDs=777777777,888888888,999999999)
 same => n,Set(rand=${RAND(1,3)})
 same => n,Set(CALLERID(num)=${CUT(CIDs,\,,${rand})})
 same => n,Goto(end,1)

exten => end,1,Set(CDR(outbound_cnum)=${CALLERID(num)})
 same => n,Return()

may be useful to someone

any advice, corrections are welcome

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.