Routing to several destinations by percentage of calls

Hi!

I have a question: regarding the handling of calls based on the percentage of incoming calls, I would like to route calls from a DID to several queues depending on the percentage of calls. In other words, 50% of calls go to queue 1 and the other 50% of calls go to queue 2. In addition, the percentage of one queue or another can be automated to modify the SLA percentage of each queue.

Use a global variable to count the number of calls.

It’s probably better to use the GROUP function than a global.

hi,
I’m testing with a global variable, i have done two cases

First Case.
Every time enter a call in dialplan,
the var1 sum one and then take the module

exten => 475,1,Answer()
same => n,Set(GLOBAL(var1)=[{var1}+1])
same => n,GotoIf([{var1}%2]>0?TEST,122,1:TEST,123,1)

Second Case:

Use func Random, when the rand function returns a value, I see if it is 0,1,2 or 3, with this it simulates a call forwarding of 40% (if it matches 0,1,2o 3) -60% (if it matches the rest)

exten => 476,1,GotoIf([{RAND(0,9)}]=0|1|2|3?TEST,122,1:TEST,123,1)

I will try to do this using GROUP as you mention, johnkiniston

Thanks!

Hi,

I think I’ll keep this way of doing it, I haven’t tried GROUP.

exten => 476,Set(var1=${RAND(0,100)})

same => n,GotoIf([{var1}>70]?go_here:) 30% of call’s
same => n,GotoIf([{var1}>50]?or_here:) 20% of call’s
same => n,GotoIf([{var1}>30]?or_here_2:) 20% of call’s
same => n,GotoIf([{var1}>0]?last_op:) 30% of call’s

correct me if this is not elegant Please.

Can you lend me a hand with this using GROUP

same => n,Set(GROUP()=XXXXX)

There are a few different ways you could handle the logic.

I would use GROUP() and GROUP_COUNT() to accurately calculate the distribution percentage.
GROUP_COUNT(group_name) / GROUP_COUNT(total_count) = percentage

You need to do the following:

  1. Prevent divide by zero
  2. GotoIf() based on the percentage
  3. Fallback Goto(), just in case there’s no match

Like the 50%, 30%, 20% and untested example below, there are intentional errors for you to fix.

[main]
exten => 476,NoOp(Percentage Distribution of Calls)
 same => n,GotoIf(${GROUP_COUNT(total)} = 0?alpha)
 same => n,GotoIf(${GROUP_COUNT(alpha)} / ${GROUP_COUNT(total)} < 0.50?alpha)
 same => n,GotoIf(${GROUP_COUNT(bravo)} / ${GROUP_COUNT(total)} < 0.30?bravo)
 same => n,GotoIf(${GROUP_COUNT(charlie)} / ${GROUP_COUNT(total)} < 0.20?charlie)
 same => n,Goto(alpha)

[alpha]
exten => _X.,1,NoOp(Trying: alpha)
 same => n,Set(GROUP()=total)
 same => n,Set(GROUP()=alpha)
 same => n,NoOp(Do Something)

[bravo]
exten => _X.,1,NoOp(Trying: bravo)
 same => n,Set(GROUP()=total)
 same => n,Set(GROUP()=bravo)
 same => n,NoOp(Do Something)

[charlie]
exten => _X.,1,NoOp(Trying: charlie)
 same => n,Set(GROUP()=total)
 same => n,Set(GROUP()=charlie)
 same => n,NoOp(Do Something)
2 Likes

works perfectly, thanks @poing!!!