A trunk with many numbers but rendom EUREKA! [SOLVED]

A trunk with many numbers

I have a trunk with a hundred numbers associated with it, it’s called GNR in Italy … I can’t translate it in English, maybe someone by what it’s called? …

However I come to the point: I would like to come out with some numbers as needed, I tried with the asterisk API specifically AMI but for now nothing …

Has anyone already addressed the problem?

Not totally understanding what you are asking for but perhaps this context is what you can start with

grep -B 10 -A 4 "\[from-did-direct\]" /etc/asterisk/extensions.conf

I don’t understand what your question is here.

Try writing in Italian and maybe @danilosm will be able to translate or help out.

1 Like

Scrivo anche in italiano:

Ho un GNR che in pratica è un trunk con molti numeri

Il cliente vorrebbe uscire tramite questo trunk ma in maniera casuale, esempio

numeri:
XXX54770
XXX54771
XXX54772
XXX54773
XXX54774

uscire una volta con XXX54771 la telefonata dopo con XXX54774 quella dopo con XXX54772 e via cosi’…

I don’t understand Italian, but I think I know what your problem is. Do you use a SIP-trunk? Try a PJSIP-trunk which better supports multiple numbers…

Don‘t know if this works
https://www.simtex.com.au/support/sip-trunking/pjsip-tips-tricks/

I believe @claloano wants outbound calls to have a Caller ID chosen randomly from a list. If so, you can adapt this dialplan, specifically the [outbound-random-cid] part: lgaetz-el_cid · GitHub

I’m curious to know what you refer to here, I can’t think of any pjsip exclusive features that support this claim.

I was wrong, of course. I just thought that I read somewhere that that’s one of the advantages of pjsip.
Here it says something about multiple servers…
https://blogs.asterisk.org/2016/01/27/the-pjsip-outbound-registration-line-option/

That’s nice. Really helps orgs with offices in multiple locations. Thank you, Lorne!

1 Like

Yes, in fact I have to go out with always different numbers starting from a list of numbers all on the same trunk
Perhaps the path indicated by Lorne Gaetz can work …

I am trying this context because it should do what I need, that is: go out with a random number among many of a trunk

[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,10)}); choose a random number between 1 and 10
exten => s, n, Noop (choosing random CID # $ {foo})
exten => s, n, goto ($ {foo}, 1)
exten => 1,1, set (CALLERID (number) = 01821985050)
exten => 2,1, set (CALLERID (number) = 01821985051)
exten => 3.1, set (CALLERID (number) = 01821985052)
exten => 4.1, set (CALLERID (number) = 01821985053)
exten => 5.1, set (CALLERID (number) = 01821985054)
exten => 6.1, set (CALLERID (number) = 01821985055)
exten => 7.1, set (CALLERID (number) = 01821985056)
exten => 8.1, set (CALLERID (number) = 01821985057)
exten => 9.1, set (CALLERID (number) = 01821985058)
exten => 10,1, set (CALLERID (number) = 01821985059)
; 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]

it’s not working for me I think because I don’t understand well what to insert in the first line:

exten => s, 1, noop (Entering user defined context outbound-random-cid in extensions_custom.conf)

[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+

; set random cid
exten => s,n,Gosub(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]

I put the text in /etc/asterisk/extensions_custom.conf

Extension 10 is configured to use the Outbound-random-cid context

[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 (Call rendom)
exten => s, n, Set (foo = $ {RAND (1,10)}); choose a random number between 1 and 10
exten => s, n, NoOp (choosing random CID # $ {foo})
exten => s, n, goto ($ {foo}, 1)
exten => 1,1, set (CALLERID (number) = 01821985050)
exten => 2,1, set (CALLERID (number) = 01821985051)
exten => 3.1, set (CALLERID (number) = 01821985052)
exten => 4.1, set (CALLERID (number) = 01821985053)
exten => 5.1, set (CALLERID (number) = 01821985054)
exten => 6.1, set (CALLERID (number) = 01821985055)
exten => 7.1, set (CALLERID (number) = 01821985056)
exten => 8.1, set (CALLERID (number) = 01821985057)
exten => 9.1, set (CALLERID (number) = 01821985058)
exten => 10,1, set (CALLERID (number) = 01821985059)
exten => _., 1, Goto (from-internal, $ {EXTEN}, 1); assuming they press 0 for the front desk
; 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]

But it always makes me go out with the 01821985050

This is not going to work.

See above solutions with using the predial hook

Try

exten => s,1,Set(CALLERID(number)=0182198${RAND(5000,10)})
same => n,Return

Important attention!
Talking to the telephone operator I got this information:
To exit with any number from the group of numbers assigned, you must use the fromuser parameter
id parameter is not needed …
I actually configured a trunt with the fonuser parameter with a number and it worked!
Now the point is how can I use the fromuser in context?
And then can I make it rendom?

I tried this but I think I am writing nonsense …

[outbound-r2]
; 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(Chiama rendom)
exten => s,n,Set(foo=${RAND(1,10)}) ;choose a random number between 1 and 10
exten => s,n,NoOp(choosing random CID #${foo})
exten => s,n,goto(${foo},1)
exten => 1,1,set(fromuser=01821985050)
exten => 2,1,set(fromuser=01821985051)
exten => 3,1,set(fromuser=01821985052)
exten => 4,1,set(fromuser=01821985053)
exten => 5,1,set(fromuser=01821985054)
exten => 6,1,set(fromuser=01821985055)
exten => 7,1,set(fromuser=01821985056)
exten => 8,1,set(fromuser=01821985057)
exten => 9,1,set(fromuser=01821985058)
exten => 10,1,set(fromuser=01821985059)
exten => _.,1,Goto(from-internal,${EXTEN},1) ; assuming they press 0 for the front desk
; 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-r2]

Are you using the predial hook?

no but it looks interesting…
In which file should I write to use predial hook?
I do not know him…

EUREKA!
solved!

[macro-dialout-trunk-predial-hook]

exten => s,1,NoOp(Chiama rendom)
exten => s,n,Set(foo=${RAND(0,9)}) ;choose a random number between 0 and 9
exten => s,n,set(fromuser=0182198505${foo})
exten => s,n,set(CALLERID(number)=0182198505${foo})
; add additional lines as necessary

; this final line is required in order to send the call flow back to the calling gosub line

; end contxt [macro-dialout-trunk-predial-hook]

@claloano Italiano - FreePBX Community Forums

1 Like