There are four applications within Asterisk that can be used to control the relationship between a queue and a member. They are AddQueueMember(), PauseQueueMember(), UnPauseQueueMember(), and RemoveQueueMember(). In this lesson we will look at adding and removing a user from a queue dynamically.
In the previous lessons we added a static member to the techteam queue by recording them in the /etc/asterisk/queue.conf file. If you want to dynamically add or remove a user from the queue, first make sure they are not already statically added to the queue.
To add the sip user matthew to the techteam queue we can create an extension that will add him. In this example I will create extenion *201. Using the AddQueueMember() application the user can be added to the queue. It is also a good idea to give some feedback to reassure the operation has been completed so I will playback the beep sounds found in the default sound files. Below is the extension to add the sip user matthew:
exten => *201,1,NoOp(Add matthew to techteam)
same => n,Answer()
same => n,AddQueueMember(techteam,SIP/matthew)
same => n,Playback(beep)
same => n,Hangup
To remove the sip user matthew from the queue we can create another extension. We can use the RemoveQueueMember() application indicating which queue and which member to remove. To provide a feedback to the user I have changed the beep sound to beeperr.
exten => *202,1,NoOp(Remove matthew from techteam)
same => n,Answer()
same => n,RemoveQueueMember(techteam,SIP/matthew)
same => n,Playback(beeperr)
same => n,Hangup
Although this option of adding and removing a member works, there are better options to program in Asterisk. This is just an easy example used to understand how dynamic queues work. There are a few problems with this method. For example, anyone on the phone system can add or remove the sip user from the queue. Also we would need to create two phone extensions for every user we wanted to participate in the queue.