Add and remove queue members using dialplan applications
The most common method to add or remove members from a queue is by using dialplan applications. This method allows agents to log in and log out themselves. The AddQueueMember application is used in a diaplan to dynamically add queue members, and the RemoveQueueMember application is used to remove them. Both applications require two parameters – the name of the queue that we would like to add a member into, and the channel we would like to add as a member.
Here is a simple dialplan code that will add a member to our sales queue when the extension *710 is dialed (we will add the following code to the [queues] context we’ve created earlier):
[queues] exten => *710,1,Verbose(2,Adding a member to the sales queue...) same => n,Set(MemberInfo=${CHANNEL(channeltype)}/${CHANNEL(peername)}) same => n,AddQueueMember(sales,${MemberInfo}) same => n,Playback(agent-loginok) same => n,Hangup()
First, we specify the variable called MemberInfo that will contain the information about the device that initiated the call (e.g. SIP/alice). Next, we execute the AddQueueMember application to add the current channel to the sales queue. The caller should then hear the agent-loginok sound.
We need to reload the dialplan in order to apply changes. If we now call the extension *710, we will get the following output in the Asterisk console:
geek-university*CLI> == Using SIP RTP CoS mark 5 -- Executing [*710@local:1] Verbose("SIP/alice-00000042", "2,Adding a member to the sales queue...") in new stack == Adding a member to the sales queue... -- Executing [*710@local:2] Set("SIP/alice-00000042", "MemberInfo=SIP/alice") in new stack -- Executing [*710@local:3] AddQueueMember("SIP/alice-00000042", "sales,SIP/alice") in new stack -- Executing [*710@local:4] Playback("SIP/alice-00000042", "agent-loginok") in new stack > 0x7f01f4008b40 -- Probation passed - setting RTP source address to 192.168.198.173:7078 -- <SIP/alice-00000042> Playing 'agent-loginok.alaw' (language 'en') -- Executing [*710@local:5] Hangup("SIP/alice-00000042", "") in new stack == Spawn extension (local, *710, 5) exited non-zero on 'SIP/alice-00000042'
We can verify that the member has indeed been added to the queue by using the queue show sales command:
geek-university*CLI> queue show sales sales has 0 calls (max unlimited) in 'rrmemory' strategy (4s holdtime, 0s talktime), W:0, C:1, A:1, SL:0.0% within 0s Members: SIP/alice (ringinuse disabled) (dynamic) (Not in use) has taken no calls yet No Callers
Now, if we use another device and call 705 (the sales queue extension), we should be placed in the queue and the queue member alice should receive the call:
geek-university*CLI> == Using SIP RTP CoS mark 5 -- Executing [705@local:1] Verbose("SIP/bob-00000043", "2,"" <bob> entered the sales queue") in new stack == "" <bob> entered the sales queue -- Executing [705@local:2] Queue("SIP/bob-00000043", "sales") in new stack -- Started music on hold, class 'default', on channel 'SIP/bob-00000043' == Using SIP RTP CoS mark 5 -- Called SIP/alice -- SIP/alice-00000044 is ringing -- SIP/alice-00000044 answered SIP/bob-00000043
As you can probably guess, the RemoveQueueMember application removes the member from a queue. In our case, the dialplan will look like this:
exten => *720,1,Verbose(2,Removing a member from the sales queue...) same => n,Set(MemberInfo=${CHANNEL(channeltype)}/${CHANNEL(peername)}) same => n,RemoveQueueMember(sales,${MemberInfo}) same => n,Playback(agent-loggedoff) same => n,Hangup()
we will reload the dialplan and then call the extension *720 using the device of the peer alice:
geek-university*CLI> == Using SIP RTP CoS mark 5 -- Executing [*720@local:1] Verbose("SIP/alice-00000045", "2,Removing a member from the sales queue...") in new stack == Removing a member from the sales queue... -- Executing [*720@local:2] Set("SIP/alice-00000045", "MemberInfo=SIP/alice") in new stack -- Executing [*720@local:3] RemoveQueueMember("SIP/alice-00000045", "sales,SIP/alice") in new stack -- Executing [*720@local:4] Playback("SIP/alice-00000045", "agent-loggedoff") in new stack > 0x7f01f40087c0 -- Probation passed - setting RTP source address to 192.168.198.173:7078 -- <SIP/alice-00000045> Playing 'agent-loggedoff.alaw' (language 'en') geek-university*CLI> -- Executing [*720@local:5] Hangup("SIP/alice-00000045", "") in new stack == Spawn extension (local, *720, 5) exited non-zero on 'SIP/alice-00000045'
We can verify that the member has indeed been removed from the queue by typing the queue show sales command:
geek-university*CLI> queue show sales sales has 0 calls (max unlimited) in 'rrmemory' strategy (7s holdtime, 0s talktime), W:0, C:2, A:1, SL:0.0% within 0s No Members No Callers