text
stringlengths
0
152
7 Perhaps we could have used / instead of - as a delimiter, giving us Local/PJSIP/SOFTPHONE_A@localMember
Connector, but we felt that would be more prone to strange syntax errors, and awkward to filter and parse, so
we went with -.
Advanced Queues
|
233
So now that we can add devices to the queue using local channels, let’s look at how
this might be useful.
Let’s say we have a customer who just can’t stand our best agent. They’re a good cus‐
tomer, so we don’t want to lose them, but it’s our best agent, so we’re not going to fire
them.
To set this up, we’re going to assign a caller ID to SOFTPHONE_B, so we have something
to match against.
MySQL> UPDATE `asterisk`.`ps_endpoints` SET callerid='SOFTPHONE_B <103>' \
WHERE id='SOFTPHONE_B';
We’re going to build a little trick into our dialplan that will reject the call to the agent
if the caller ID matches our sensitive customer.
[localMemberConnector]
exten => _[A-Za-z0-9].,1,Verbose(2,Connect ${CALLERID(all)} to Agent at ${EXTEN})
same => n,Wait(0.1) ; Prevent loop from completely hogging CPU
same => n,Set(QueueMember=${FILTER(A-Za-z0-9\-_,${EXTEN})}) ; allow alphanum, - , _
same => n,Set(Technology=${CUT(QueueMember,-,1)}) ; first field, hyphen is separator
same => n,Set(Device=${CUT(QueueMember,-,2)}) ; second field, hypen separator
; is this our mismatched pair?
same => n,DumpChan()
same => n,Noop(${CALLERID(all)} : ${Device})
same=>n,GotoIf($["${CALLERID(num)}"="103"&"${Device}"="SOFTPHONE_A"]?rejectcall:ringagent)
; dial the agent
same => n(ringagent),Dial(${Technology}/${Device})
same => n,Hangup()
; send it back!
same => n(rejectcall),Congestion()
same => n,Hangup()
The passing back of Congestion() will cause the caller to be returned to the queue
(while this is happening, the caller gets no indication that anything is amiss and keeps
hearing music until their call is answered by a channel of some sort).8 Ideally, your
queue is programmed to try another agent; however, you need to keep in mind that if
app_queue determines that this member is still its first choice to present the call to,
the call will simply be reconnected to the same agent (and get congestion again, and
thus potentially create a CPU-hogging logic loop). To avoid this, you will need to
ensure your queue is using a distribution strategy such as round_robin, random, or
any strategy that ensures the same member is not tried over and over. This is also why
we toss a tiny little delay into our [localMemberConnector] context, so if a loop like
this does happen, there’s at least a small throttle on it.
Let’s just sanity check our code. Set the caller ID number to something other than
103, and the call should go through.
8 Obviously, don’t use any dialplan code in your local channel that will answer, such as Answer(), Playback(),
and so forth.
234
|
Chapter 12: Automatic Call Distribution Queues
MySQL> UPDATE `asterisk`.`ps_endpoints` SET callerid='SOFTPHONE_B <123>' \
WHERE id='SOFTPHONE_B';
The use of local channels for your member channels will not make queue design and
debugging easier, but it does give you far more power over your queues than just
using app_queue on its own, so if you have a complex queue requirement, the use of
local channels will give you a level of control you would not have otherwise.
Queue Statistics: The queue_log File
The queue_log file (commonly located in /var/log/asterisk) contains cumulative event
information for the queues defined in your system (such as when a queue is reloaded,
when queue members are added or removed, pause/unpause events, and so forth) as
well as some call details (e.g., their status and which channels the callers were connec‐
ted to). The queue log is enabled by default, but it can be controlled via the /etc/aster‐
isk/logger.conf file. There are three options related to the queue_log file specifically:
queue_log
Controls whether the queue log is enabled or not. Valid values are yes or no
(defaults to yes).
queue_log_to_file
Controls whether the queue log should be written to a file even when a real-time
backend is present. Valid values are yes or no (defaults to no).
queue_log_name
Controls the name of the queue log. The default is queue_log.
The queue log is a pipe-separated list of events. The fields in the queue_log file are as