When a persistent queue member is dynamically added to the queue, an entry is added to the database within Asterisk. To view a list database entries use the following command in the CLI:
database show |
For a member that has been dynamically added to the techteam queue, there should be a database key that reads: /Queue/PersistentMembers/techteam. The value associated with the key (located to the right of the key) will indicate the user account added to the queue.
There are two useful functions that we can use to work with the database from the dialplan, DB() and REGEX(). The DB() function provides access to the database and the REGEX() function searches for a value.
The REGEX() function can take two parameters, first the string characters you are searching for and second the item you are searching in. We will use the DB() function to provide searching the value of the /Queue/PersistentMembers/techteam key.
Combining these functions with the GotoIf() application we can check to see if a queue member has been added to the database. If they haven’t we can add them, and if they have we can remove them.
Add the following to the dialplan to add extension 800:
exten => 800,1,NoOp(chaz login/logout of techteam) same => n,GotoIf(${REGEX("SIP/chaz",${DB(Queue/PersistentMembers/techteam)})}?800-logout,1:800-login,1) same => n,Hangup |
Based on the code of the GotoIf() application in the previous extension, if “SIP/chaz” exists in the database we will redirect to the first line of code in extension 800-logout. If “SIP/chaz” was not found in the database it will redirect to the first line of code in extension 800-login.
We will now need to create both extension 800-logout and 800-login to dynamically add or remove the member from the queue. Add the following code to the dialplan:
exten => 800-logout,1,NoOp(chaz exists, logout) same => n,RemoveQueueMember(techteam,SIP/chaz) same => n,Playback(beep) same => n,Hangup |
exten => 800-login,1,NoOp(chaz doesn't exist, login) same => n,AddQueueMember(techteam,SIP/chaz) same => n,Playback(beep) same => n,Hangup |
No that we can essentially add or remove a user by dialing the same extension, we have made it easier for our members to add or remove themself. We still have the issue of having to create this same setup for each user of the queue. In the next lesson we will change the code so that user who is calling the extension will be added or remove to queue.