Asterisk dialplan : random naviguation
Sometimes, you want your callers to go randomly to a place.
For example, you have 5 extensions and you want inbound calls to be send randomly to those extensions.
You may want a equal distribution or distribution based on a certain probability.
Another case where this can be usefull is if you have multiple carriers and want to send your outbound calls randomly to them.
To do so, you can use the asterisk RAND function.
[Syntax]
RAND([min][|max])[Synopsis]
Choose a random number in a range[Description]
Choose a random number between min and max. Min defaults to 0, if not
specified, while max defaults to RAND_MAX (2147483647 on many systems).
Example: Set(junky=${RAND(1|8)});
Sets junky to a random number between 1 and 8, inclusive.
Action
In the following example, we receive a call to DID number 5140000000 and want to send 60% to SIP extension 2200 and the rest to extension 3300. The dialplan the looks like
exten => 5140000000,1,Noop(New call received from ${CALLERID(all)})
exten => 5140000000,n,GotoIf($[${RAND(1,100)} > 40]?labelagt1)
exten => 5140000000,n(labelagt2),Dial(SIP/3300)
exten => 5140000000,n,Hangup
exten => 5140000000,n(labelagt1),Dial(SIP/2200)
exten => 5140000000,n,Hangup
So, basicly, when we receive the call, we generate a random number between 0 and 100.
If that number is more than 40 (should happen 60% of the time), we go to priority with label ‘labelagt1′ and we dial SIP/2200.
If not (should happen 40% of the time), we go the next priority and dial SIP/3300.
Comments
Leave a Reply