Nov 15, 2016

How to Set Up IVR Functionality on Asterisk

Interactive voice response (IVR) is a technology that allows a computer to interact with humans through the use of voice and DTMF tones input via keypad. Setting up an IVR functionality on Asterisk is pretty much simple, but you will need to be a little techie to make it functional.





We will be setting up live phone number, when called, prompts the user to "press 1 for Sales, 2 for Tech Support and 3 for Billing department". If the caller presses one the call will be transferred to the sales number, if they press 2 the call will be connected to tech support and so on.

In this guide, we will walk you through the steps to configure an IVR server on asterisk using Ubuntu or Debian Linux.

 

IVR Set Up Overview

First we need to download and install Asterisk, then we will build out an "Asterisk Dialplan" (this is simply the program that tells Asterisk what we want our IVR to do), we will then use the softphone Linphone (ie: phone on our computer) to test our IVR application to make sure it's all working properly.
Lastly if we want to take your IVR system live, we will setup a real phone number (to handle inbound calls) and a SIP trunk (to handle outbound call). Because we work at RingRoost, we will use them as our inbound/outbound call carrier in this example, you may of course use any carrier that suits your environment. 

 

Installing Asterisk

Make sure you have the most recent flavor of Linux installed. I'll be using an Ubuntu 14.04 machine in this example. We have already covered step by step installation and configuration guide in our earlier article How to Install Asterisk on RHEL, CentOS, Fedora or Ubuntu. Please go through it.

To install asterisk on Ubuntu or Debian Linux, you need to run following command:
 
apt-get install asterisk 
 
If you get the error message: "Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?"
 
Run:
apt-get update && apt-get install asterisk 

Make sure asterisk is running by trying to connect to the Asterisk client by running:
 
asterisk -rvvvvvvvv

 

Building Our IVR

Now, lets build out the IVR. To keep things simple at first we are just going to have our IVR say a few digits, this way we can connect to the IVR and make sure everything is working.

Edit your Asterisk sip.conf file found at "/etc/asterisk/sip.conf" in your favorite editor and put the below code in it. Note: make backup of sip.conf and remove all code that is currently in the sip.conf file. If the file does not exist, create it.

/etc/asterisk/sip.conf

[general]
bindaddr = 0.0.0.0
context = my_ivr_menu 
host=dynamic
type=friend 

Now, edit your Asterisk extensions.conf file found at "/etc/asterisk/extensions.conf" and add the below code in it. Note: make backup and remove all code that is currently in the extensions.conf file. If the file does not exist, create it.

/etc/asterisk/extensions.conf

[my_ivr_menu]
exten => 30,1,Answer()
exten => 30,2,SayDigits(1234)
exten => 30,3,Hangup()
We now need to restart asterisk in order for it to know about the changes we made. From the asterisk cli console run:
 
core restart now  
Then connect to asterisk again:
 
asterisk -rvvvvvvvv 

Now for testing, we need to install a softphone. We will use Linphone which you can download here: http://www.linphone.org/downloads-for-desktop.html .

We will now dial into our asterisk server on Linphone. In the "SIP address" bar input "sip:30@asteriskipaddresshere" and dial it (green icon). You should hear a voice say 1234.


Notice that we are dialing the extension "30" this could be any number, I just chose a random extension.

 

Setting up 1,2,3 options menu

Now that we know things are working, we will dive a little deeper and get real IVR going. Now replace the code in your "/etc/asterisk/extensions.conf" file with the below code: 

/etc/asterisk/extensions.conf

[my_ivr_menu]
exten => 30,1,Answer()
exten => 30,2,Background(/var/lib/asterisk/sounds/ivr_promt_user)
exten => 30,3,Hangup()

exten => 1,1,Playback(/var/lib/asterisk/sounds/sales_message)
exten => 1,2,Hangup()

exten => 2,1,Playback(/var/lib/asterisk/sounds/tech_message)
exten => 2,2,Hangup()

exten => 3,1,Playback(/var/lib/asterisk/sounds/billing_message)
exten => 3,2,Hangup()

You will notice we are playing some audio files on asterisk. You can of course change this audio files to play whatever you want. You can download the audio files for this example here.

You will then need to unzip and upload the 4 audio files into "/var/lib/asterisk/sounds/" directory on your asterisk server.

Now reload your extensions.conf file by typing the below command into the asterisk cli.
 
dialplan reload
Now dial into your IVR again and try it out by pressing 1,2,3. 


Note: Linephone (annoyingly) appends what you dial to the "SIP" address so if you hangup and try to dial in again make sure your IP address does not have the appended digits on it.

 

Going live with an inbound phone number

First, we need to do is get a phone number with RingRoost and point that number to our Asterisk box. You will need to create a RingRoost account here , if you don't have one , add some funds to get started, and then order a number under the number tab here .
 If you are unfamiliar with how RingRoost Works here is quick intro video.

Now on your RingRoost PBX builder drag and drop an "Answer Call" control onto your PBX and select your phone number. Then drag and drop a "Dial Control" onto your PBX and connect it with the "Answer Call" control. In the "Dial" Control remove the phone number and add "SIP Address" with "30@youripddresshere" as the SIP address value. It should look like this:


Save your PBX and then call your phone number from any phone. You should hear the prompt and be able to press 1, 2 or 3 and hear that department's message.

 

Going live with outbound dialing

Lastly, we need our system to actually dial phone numbers in order to connect with a particular department - simply telling a person they reached a department does not do much good.

First we need to drag and drop a "SIP Phone" control onto our PBX and save it. We will use this as our outbound trunk. Make note of the "Sip User" & "Sip Password" fields (make sure to keep these safe).

We will need to change our "/etc/asterisk/sip.conf" file to look like the below example. You will need to change "sip_user_here" and "sip_password_here" to your SIP username/password.

/etc/asterisk/sip.conf

[general]
bindaddr = 0.0.0.0
context = my_ivr_menu 
host=dynamic
type=friend                                                                                                           
register => sip_user_here:sip_password_here@ringroost.com                                                                   

[ringroost]                                                                                                           
host=ringroost.com
type=friend
secret=sip_password_here                                                                                                   
username=sip_user_here
disallow=all 
allow=ulaw 
allow=g729 

We also need to change our "/etc/asterisk/extensions.conf" file to look like this:

/etc/asterisk/extensions.conf

[my_ivr_menu]                                                                                                         
exten => 30,1,Answer()                                                                                                
exten => 30,2,Background(/var/lib/asterisk/sounds/ivr_promt_user)                                                     
exten => 30,3,Hangup()                                                                                                
                                                                                                                      
exten => 1,1,DIAL("SIP/17049448765@ringroost")                                                                        
exten => 1,2,Hangup()                                                                                                 
                                                                                                                      
exten => 2,1,DIAL("SIP/17049448765@ringroost")                                                                        
exten => 2,2,Hangup()                                                                                                 
                                                                                                                      
exten => 3,1,DIAL("SIP/17049448766@ringroost")                                                                        
exten => 3,2,Hangup() 
Then Restart Asterisk:
 
core restart now  

Note: Change the phone numbers to be whatever numbers you want to call. 






Now go ahead and call your Ringroost phone number and try out your new IVR call system. Now when someone presses 1,2,3 they will be connected to that particular phone number instead of just hearing a recording.

Post a Comment

 
TECH SUPPORT © 2012 - Designed by INFOSBIRD