This tutorial will show you how to create a queue, where your incoming calls to arrive. Noting so special, but we are also going to show you how to give a choice to the callers - they will be able to leave the queue at any time and in our example they will have the choice to leave a number at which you could callback them later. The best part is that the number will be nicely emailed to your email box with details not only about the left number, but also the CallerID, the queue at which the caller was initially placed and the date and time at which he has left his number.
We will show you how to create your extensions in extensions.conf.
To test how the setup works we recommend to use our IAX softphone Idefisk. You can download it from our website - here. If you do so, you can also take a look at our tutorial about how to configure it to work with Asterisk PBX.
For the sending of the emails you will need to install the mime-construct package. apt-get install mime-construct (in Debian) should do the trick. Of course you will need a SMTP server too.
3. Asterisk PBX configurations
We need to create one user in the iax.conf file. This is because we are going to use Idefisk and its IAX2 support. Idefisk supports the SIP protocol too. So if you want to use it, you have to do the configurations below respectively in sip.conf.
Type=friend means that this user can make and receive calls. Host=dynamic means that the IP is not statically assigned but dynamically through a DHCP server. Allow=all means that the line which this user will use, support all available audio codecs, supported by Asterisk. Context=test - this shows that the user is allowed to work with the extensions in the context with this name in the configuration file extensions.conf.
member => IAX2/user1
member => IAX2/user2
member => IAX2/user3
member => IAX2/user4
member => IAX2/user5
member => IAX2/user6
member => IAX2/user7
member => IAX2/user8
member => IAX2/user9
member => IAX2/user1
member => IAX2/user2
member => IAX2/user3
member => IAX2/user4
member => IAX2/user5
member => IAX2/user6
member => IAX2/user7
member => IAX2/user8
member => IAX2/user9
member => IAX2/user1
member => IAX2/user2
member => IAX2/user3
member => IAX2/user4
Now let’s take a look at the shell script you will need if you want to send emails with the left number. The script will use the mime-construct program to create the email message and send it to the desired recipient. The second script has the same purpose and the only change is in the body of the email message.
Here are the configurations:
Script 1:
#!/bin/sh
NUMBER=$1
RECIPIENT=$2
CALLERID=$3
QUEUE=$4
mime-construct --to $RECIPIENT --subject "You have just missed a call" --string "The number that have been left by the caller: $NUMBER. The CallerID we have received: $CALLERID. The call is coming from the $QUEUE queue. Call was received at `date`"
Script 2:
#!/bin/sh
RECIPIENT=$1
CALLERID=$2
QUEUE=$3
mime-construct --to $RECIPIENT --subject "You have just missed a call" --string "The caller did not left a telephone number. The CallerID we have received: $CALLERID. The call is coming from the $QUEUE queue. Call was received at `date`"
4. Explanation
Now, we are going to explain you what the configurations about actually means and how it works.
However, keep in mind that we are going to explain you only the configurations concerning the Callback possibility. If you want to learn more about the used configuration files and their options - take a look at one of our tutorials:
In the example above you could see three different queues each one with different number of agents.
Each queue has its own configuration. Most of the settings are common, unless one option - the context.
This option is giving you the possibility to define a context, where eventually, by pressing a single digit, the caller will be "transferred". The digit could be pressed at any time while the caller is waiting in the queue. The context we are talking about has to be created in the extensions.conf configuration file. There is one more requirement and it is that you have to create an extension of one digit, in this context - the digit that the caller will press in order to exit the queue.
Despite of the fact, that for all the queues, the setup for leaving a number and then emailing it to our email address will be pretty much the same, we recommend you to create different contexts for every different queue. That is because we are going to email not only the left number but also some other information such as the queue from which the caller has quitted. Of course you could do it with one common and more complicated context for all the queues, but we think that it will be much easier to manage and change the settings for each queue independently of the other ones.
So here are all the options in our queue and what they are doing"
music = default - the music class defined in musiconhold.conf, where Asterisk will be looking for mp3 files, which will be played to the caller instead of ringing tone, while he is waiting in the queue. strategy = ringall - one of six ringing strategies that you could choose. This one means the phone of each agent, assigned to the queue, will start ringing in case of incoming call. For details about the other strategies take a look at our tutorial about queues.conf timeout=15 - a timeout in seconds. It defines after how many seconds with no answer the agent phone to stop ringing. For more information about refer to our tutorial about queues.conf . retry = 5 - after how many seconds to try to ring all the agents again. For more information about refer to our tutorial about queues.conf. context = queue3out - we have already explained this above. periodic-announce-frequency = 60 - define in seconds an interval of time after which the caller, waiting in the queue, will hear a prerecorded message. It could be a message with instructions or something else. It is up to you. For more information about refer to our tutorial about queues.conf. periodic-announce = Call_Back_1 - that is the name of the prerecorded message that should be played after the periodic announce timeout expires. For more information about refer to our tutorial about queues.conf.
member => IAX2/user1 - there are two different ways to assign agents to a specific queue. We have picked up the easies one. Whenever a phone with username user1 is registered successfully to the Asterisk system, the incoming calls in the queue will be send to this phone. You could have as many as you want agents assigned to the queue in this way and the incoming call will be send to all of them according to the chosen strategy. For more information about refer to our tutorial about queues.conf.
Now let's take a look at the configurations in extensions.conf.
First of all we have three extensions for the incoming calls. They are all put in the [incoming_calls] context. Their purpose is to put the incoming calls in the corresponding queue.
When we have an incoming call, the first thing we are doing is to change the Callerid name to the name of the queue where the caller will be put. Thus the agent who is answering the call will know from which queue exactly the call is coming. It is not absolutely necessary, but the idea is that one agent could be assigned to many different queues. In order to do the change we are using the Set application - More information about it in our tutorial
Next step is to create the contexts, where the callers should be "transferred" in case they have decided to exit the queue. As we have mentioned above we have different context for each of the queue.
Before we continue - a few words about the idea behind. We are running queues with a callback option. In other words, when we have a caller waiting in the queue, we will play him a message every 60 seconds. The message will saying: "All of our lines are busy. You could leave your number by pressing one and we will call you back as soon as possible or you could stay in the queue and wait to be served.".
If the caller decides to exit the queue, he will be asked to leave his number after the "beep" signal. At this stage, you have to keep in mind that the caller might not leave his number for some reason. So what we will have a check and if the number is not left we will send an email message that the caller has decided not to leave his number.
So what do we need as extensions? The first thing we are doing is to set a flag. Why? In case the caller hangs up at some point before leaving his number, we need to send a message that we did not received the number. For the purpose we are using the so called predefined extension - h, which allows you to execute something in case of hang up. Refer to our tutorial for more information
However, there is a slight chance that the caller might wait for the timeout to expires without leaving his number or to have a problem with the sending of DTMF tone, that we will have an email saying that the caller has left his number but the number field will be empty and because we have a hang up event even if the caller has left his number, we need the flag to determine whether the hang up is before the application that will store the number or after it and on that basis we will know whether we need to send an email message on hang up or not. In this way we omit the sending of one message twice.
On the next step we have the Playback application. Its simple purpose is to play a sound files. We have a sound message, which instructs the caller to type his number after the beep tone and to press the pound key (#) when he is ready. For more information refer to our tutorial about the Playback application
Next, comes the Read application. It’s the one used to store the number typed by the caller. It has many options.
There is a small limitation in the application we are going to use to save the number typed by the caller. We need to know, when he has finished with the typing. So there are two ways.
The first one is to ask him to press the pound key (#) once he is ready and the second one is to limit the length of the number the caller could type plus a timeout.
In our example we are going to limit the length of the number to 10 digits and we are going to put a timeout of 5 seconds. We are going to store the number typed by the caller in the NUMBER variable. The Read application gives you the possibility to play a sound file before the typing of the number. In our case we will are going to play a beep tone
Next steps - we have the Wait application, which is not absolutely necessary and then we set the flag variable to 2. This, as we have already described above will be used to omit the sending of one and the same email message twice. For more information about the Wait application, refer to our tutorial.
We now have to check whether the caller has actually left his number or not. For the purpose we can use the GoToIf application. It has a very specific syntax, but its idea is simple to verify whether one condition is true or false. So, in our case we are just checking whether the NUMBER variable is empty or not. If it is empty then the execution of the dialplan will continue with the next step, marked as n(empty). n makes your life easier as you do not have to write and follow the steps (priorities) - n means that you take the previous priority and increase it with 1. (empty) is a label showing to you and the system to which n you will be send.
Both steps (empty) and (full) have one and the same task - to execute the shell script, which will form the email message and send it. The only difference would be in the body of the email message. The application, which we have to use is called System. It just executes system commands as you will do it in your Linux CLI. Refer to our Tutorial for more information about the System application.
In our case we are executing our own scripts called mailnumber and mailnonumber. They are written in such way that we have to pass them a few parameters. You could see them above as screenshots and in pure text
If we do not have the caller's number, we will execute the script called mailnonumber. We need to add, as first parameter, the email address of the recipient. The second parameter is the CallerId number as we have received it in our system. The last parameter is the name of the queue from which the caller has exited.
If we have the caller's number we will have executed another shell script called mailnumber which has a different body, but the same parameters plus one more, which of course is the number left by the caller.
The sending of the email is the last step we need to do and that is why after it we have to hang up the channel. For the purpose we will use once again the Hangup application.
In the predefined extensions starting with h we have a simple check of the FLAG variable to help use determine whether we have to send an email with saying that we do not have the caller's number. (this step is only needed in case the caller hangs up before the prompt to leave his number)
A few words about the shell scripts.
They are not very complicated. All you need is a basic knowledge of shell scripts and the mime-construct package. apt-get install mime-construct (in Debian) and you will have it. Then its just up to the mime-construct's syntax
Now all you have to do is to register your IAX2 base softphone Idefisk to your Asterisk system with the settings, shown above, in iax.conf and dial one of the extensions created in the [incoming_calls] context.
What will happen (if you have followed our setup) is that you will be put in a queue and on every 60 seconds you will hear a message saying that you could exit the queue and leave your number by pressing 1. If you press one you will hear a prompt to leave you number after the signal. Then you will hear beep and if you leave your number followed by the pound key (#), the number will be emailed to the desired email address and you will probably receive a callback.
Hai le xuan (lxhai06 at yahoo dot com) 21 August 2008 12:45:52 Hi, help me
How to create Call Forward on Busy in Asterisk ?
Example :
Register :*96 telephone number #
Cancel :*97#
nas (haydi_nas at hotmail dot com) 09 June 2007 17:08:32 Good morning,I'm a student from Algeria and I want to know how to add comments to extension.conf.
Thank you
Zsolt Gera (geraz at portalnet dot hu) 17 May 2007 07:14:05 Hi,
Sreeraj.K.G (sreerajganga at rediffmail dot com) 18 April 2007 18:51:16 Is queuemetrics enough for call management.I have installed and configured Trixbox 2 and configured.My server working fine now.I want to add Callmanagement tool too.So plz help me.
Thanks
Sreeraj.K.G
souvik (souvik_sadhu at yahoo dot com) 27 February 2007 08:53:32 Hi..
I am a new asterisk user.
I have configured asterisk and i can make call via soft phone.
Now, i want to make a local call.
i m having TDM11B card. So what i have to do ,if i want to call from my phonw which is connected via FXS.
And if i want to make a call to my FXS ph extension no.
Please let me know how to configur it??
Please reply via my mail id
souvik_sadhu@yahoo.com