Changing dynamicly Callerid with While()

Hi All,

I try to change callerid for every call as dynamic but loop is continue
anyone help ?

For example dial plan;

[NUMARALAR]
exten => cell1,1,Set(CALLERID(num)=02324240943)
same => n,Return
exten => cell2,1,Set(CALLERID(num)=02422121548)
same => n,Return
exten => cell3,1,Set(CALLERID(num)=02422384086)
same => n,Return
exten => cell4,1,Set(CALLERID(num)=02422385037)
same => n,Return
exten => cell5,1,Set(CALLERID(num)=02524240679)
same => n,Return
exten => cell6,1,Set(CALLERID(num)=02524240742)
same => n,Return
exten => cell7,1,Set(CALLERID(num)=02566100792)
same => n,Return
exten => cell8,1,Set(CALLERID(num)=02566100821)
same => n,Return
exten => cell9,1,Set(CALLERID(num)=02566100836)
same => n,Return
exten => cell10,1,Set(CALLERID(num)=02566100851)
same => n,Return
exten => cell11,1,Set(CALLERID(num)=03124650481)
same => n,Return

;–== end of [NUMARALAR] ==–;

[ext-did-0001]
include => ext-did-0001-custom
exten => fax,1,Goto(${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)})
exten => s,1,ExecIf($["${FROM_DID}" = “”]?Set(__FROM_DID=${EXTEN}))
exten => s,n,Gosub(app-blacklist-check,s,1())
exten => s,n,Set(CDR(did)=${FROM_DID})

exten => s,n,Set(i=1)
exten => s,n,While($[${i}<11])
exten => s,n,Gosub(NUMARALAR,cell${i},1)
exten => s,n,Set(i=$[${i} + 1])
exten => s,n,ContinueWhile()

exten => s,n,Set(CHANNEL(musicclass)=default)
exten => s,n,Set(__MOHCLASS=default)
exten => s,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => s,n,Set(CALLERPRES()=allowed_not_screened)
exten => s,n(dest-ext),Goto(ext-trunk,2,1)

;–== end of [ext-did-0001] ==–;

Maybe I’m misunderstanding what you are trying to do here, but why do you want to change your caller ID 11 times before you place the call?

it is needed :slight_smile:
I dont want to change 11 times before the call that is problem
I want to change caller id for per call that config is mistaken
How can I do?

It’s trivially obvious that any use of while will result in 11 changes, but I’m having trouble thinking of a legitimate reason for switching between multiple caller IDs.

The only use case I can think of involves avoiding spam blockers.

Try: RAND()

[RANDOM-CLID]
exten => _X.,1,NoOp(Set Random CLID)
 same => 2,Goto(${RAND(3,5)})
 same => 3,Goto(AAA,${EXTEN},1)
 same => 4,Goto(BBB,${EXTEN},1)
 same => 5,Goto(CCC,${EXTEN},1)

[AAA]
...
 same => n,Set(CALLERID(num)=NPANXX0000)
 same => n,Dial()

[BBB]
...
 same => n,Set(CALLERID(num)=NPANXX0000)
 same => n,Dial()

[CCC]
...
 same => n,Set(CALLERID(num)=NPANXX0000)
 same => n,Dial()

I think your solution could be optimized down to work with his code as a single line of:

exten => s,n,Gosub(NUMARALAR,cell${RAND(1,11)},1)

Thanks Point but I have worked with RAND() func before while() but I want to change callerid one by one
is it possible?

Thanks Johnkiniston but I want to change callerid one by one in order

So you’re not looking for RAND(). You need apply a loop using a global variable. Ah ha!, That’s why you have while() in the topic title.

[globals]
CLID=3

[clid-setting]
exten => _X.,1,NoOp(Set Sequential CLID)
 same => 2,Set(GLOBAL(CLID)=IF($[${CLID} > 6]?4:${CLID}+1))
 same => 3,Goto(${CLID)})
 same => 4,Goto(AAA,${EXTEN},1)
 same => 5,Goto(BBB,${EXTEN},1)
 same => 6,Goto(CCC,${EXTEN},1)

Note: This is untested, you need to be sure the global variable is applied properly.

There are race conditions in the above code sample, but I don’t want to go into further details until I know the real purpose.

I tested but callerid not changed in order, every placed the call same with callerid
Debuging;

Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
– Executing [5xxxxxxxx@from-trunk-sip-ININ-slave:1] Set(“SIP/ININ-slave-002c604c”, “GROUP()=OUT_5”) in new stack
– Executing [5xxxxxxxx@from-trunk-sip-ININ-slave:2] Goto(“SIP/ININ-slave-002c604c”, “from-trunk,5xxxxxxxx,1”) in new stack
– Goto (from-trunk,5xxxxxxxx,1)
– Executing [5xxxxxxxx@from-trunk:1] NoOp(“SIP/ININ-slave-002c604c”, “Catch-All DID Match - Found 5xxxxxxxx - You probably want a DID for this.”) in new stack
– Executing [5xxxxxxxx@from-trunk:2] Set(“SIP/ININ-slave-002c604c”, “__FROM_DID=5xxxxxxxx”) in new stack
– Executing [5xxxxxxxx@from-trunk:3] Goto(“SIP/ININ-slave-002c604c”, “ext-did,s,1”) in new stack
– Goto (ext-did,s,1)
– Executing [s@ext-did:1] ExecIf(“SIP/ININ-slave-002c604c”, “0?Set(__FROM_DID=s)”) in new stack
– Executing [s@ext-did:2] Gosub(“SIP/ININ-slave-002c604c”, “app-blacklist-check,s,1()”) in new stack
– Executing [s@app-blacklist-check:1] GotoIf(“SIP/ININ-slave-002c604c”, “0?blacklisted”) in new stack
– Executing [s@app-blacklist-check:2] Set(“SIP/ININ-slave-002c604c”, “CALLED_BLACKLIST=1”) in new stack
– Executing [s@app-blacklist-check:3] Return(“SIP/ININ-slave-002c604c”, “”) in new stack
– Executing [s@ext-did:3] Set(“SIP/ININ-slave-002c604c”, “CDR(did)=5xxxxxxxx”) in new stack
– Executing [s@ext-did:4] Gosub(“SIP/ININ-slave-002c604c”, “NUMARALAR,cell2,1”) in new stack
– Executing [cell2@NUMARALAR:1] Set(“SIP/ININ-slave-002c604c”, “CALLERID(num)=024xxxxxxxx”) in new stack
– Executing [cell2@NUMARALAR:2] Return(“SIP/ININ-slave-002c604c”, “”) in new stack
– Executing [s@ext-did:5] Set(“SIP/ININ-slave-002c604c”, “CHANNEL(musicclass)=default”) in new stack
– Executing [s@ext-did:6] Set(“SIP/ININ-slave-002c604c”, “__MOHCLASS=default”) in new stack
– Executing [s@ext-did:7] Set(“SIP/ININ-slave-002c604c”, “__CALLINGPRES_SV=allowed_not_screened”) in new stack
– Executing [s@ext-did:8] Set(“SIP/ININ-slave-002c604c”, “CALLERPRES()=allowed_not_screened”) in new stack
– Executing [s@ext-did:9] Goto(“SIP/ININ-slave-002c604c”, “ext-trunk,2,1”) in new stack
– Goto (ext-trunk,2,1)
– Executing [2@ext-trunk:1] Set(“SIP/ININ-slave-002c604c”, “TDIAL_STRING=SIP/ILG3”) in new stack
– Executing [2@ext-trunk:2] Set(“SIP/ININ-slave-002c604c”, “DIAL_TRUNK=2”) in new stack
– Executing [2@ext-trunk:3] Goto(“SIP/ININ-slave-002c604c”, “ext-trunk,tdial,1”) in new stack
– Goto (ext-trunk,tdial,1)
– Executing [tdial@ext-trunk:1] Set(“SIP/ININ-slave-002c604c”, “OUTBOUND_GROUP=OUT_2”) in new stack
– Executing [tdial@ext-trunk:2] GotoIf(“SIP/ININ-slave-002c604c”, “1?nomax”) in new stack
– Goto (ext-trunk,tdial,4)
– Executing [tdial@ext-trunk:4] ExecIf(“SIP/ININ-slave-002c604c”, “1?Set(CALLERPRES()=allowed_not_screened)”) in new stack
– Executing [tdial@ext-trunk:5] Set(“SIP/ININ-slave-002c604c”, “DIAL_NUMBER=5xxxxxxxx”) in new stack
– Executing [tdial@ext-trunk:6] GosubIf(“SIP/ININ-slave-002c604c”, “1?sub-flp-2,s,1()”) in new stack
– Executing [s@sub-flp-2:1] ExecIf(“SIP/ININ-slave-002c604c”, “1?Return()”) in new stack
– Executing [tdial@ext-trunk:7] Set(“SIP/ININ-slave-002c604c”, “OUTNUM=5xxxxxxxx”) in new stack
– Executing [tdial@ext-trunk:8] Set(“SIP/ININ-slave-002c604c”, “DIAL_TRUNK_OPTIONS=”) in new stack
– Executing [tdial@ext-trunk:9] Dial(“SIP/ININ-slave-002c604c”, “SIP/ILG3/5xxxxxxxx,300,”) in new stack

DialPlan

[globals]
CLID=2
;end of [globals]

[ext-did-0001]
include => ext-did-0001-custom
exten => fax,1,Goto(${CUT(FAX_DEST,^,1)},${CUT(FAX_DEST,^,2)},${CUT(FAX_DEST,^,3)})

exten => s,1,ExecIf($["${FROM_DID}" = “”]?Set(__FROM_DID=${EXTEN}))
exten => s,n,Gosub(app-blacklist-check,s,1())
exten => s,n,Set(CDR(did)=${FROM_DID})

exten => s,Set(GLOBAL(CLID)=IF($[${CLID} < 11]?4:${CLID}+1))
exten => s,n,Gosub(NUMARALAR,cell${CLID},1)

exten => s,n,Set(CHANNEL(musicclass)=default)
exten => s,n,Set(__MOHCLASS=default)
exten => s,n,Set(__CALLINGPRES_SV=${CALLERPRES()})
exten => s,n,Set(CALLERPRES()=allowed_not_screened)
exten => s,n(dest-ext),Goto(ext-trunk,2,1)

;–== end of [ext-did-0001] ==–;

[NUMARALAR]
exten => cell1,1,Set(CALLERID(num)=02324240943)
same => n,Return
exten => cell2,1,Set(CALLERID(num)=02422121548)
same => n,Return
exten => cell3,1,Set(CALLERID(num)=02422384086)
same => n,Return
exten => cell4,1,Set(CALLERID(num)=02422385037)
same => n,Return
exten => cell5,1,Set(CALLERID(num)=02524240679)
same => n,Return
exten => cell6,1,Set(CALLERID(num)=02524240742)
same => n,Return
exten => cell7,1,Set(CALLERID(num)=02566100792)
same => n,Return
exten => cell8,1,Set(CALLERID(num)=02566100821)
same => n,Return
exten => cell9,1,Set(CALLERID(num)=02566100836)
same => n,Return
exten => cell10,1,Set(CALLERID(num)=02566100851)
same => n,Return
exten => cell11,1,Set(CALLERID(num)=03124650481)
same => n,Return

The debug does not show Set() happening before Gosub(NUMARALAR).
I said it was untested, make sure the IF() logic is correct.
Make sure the global variable assignment method if correct for your Asterisk version.
You need to be careful with channel variable vs. global variable.

My asterisk ver. is = Asterisk 11.13.0 currently running

exten => s,Set(GLOBAL(CLID)=IF($[${CLID} < 11]?4:${CLID}+1))
what does it mean “?4:${CLID}+1))”

especially question mark(?)

“?” is regex
ok poing

It’s part of the evaluation. Separating the condition and true action.

If(condition?true:false)

It would look like this in another language.

if (condition) {
    true
} else {
    false
}

Maybe this will help.

if ($CLID > 11) {
    // Set to the low value
    GLOBAL(CLID) = 4
} else {
    // Increase by one (1)
    GLOBAL(CLID) = $CLID++
}

understanded thank you Poing
I try to “If” func

exten => s,Set(GLOBAL(CLID)=IF($[${CLID} > 11]?1:${CLID}+1)) is working but not increase +1 next call

it worked!
exten => s,n,Set(GLOBAL(CLID)=${IF($[${CLID} > 11]?1:$[${CLID}+1])})
it could not work with Arithmetic operators ${CLID}+1))

thank a lot