IVR is an Interactive Voice Response which takes input from a caller, perform an action based on that input, and return a result to the caller. Traditionally, IVR systems have been very complex and expensive to implement. The aim of this tutorial is to showcase simple way to get IVR in Asterisk system.
This is a continuation of Tutorials on Asterisk and Software based PBX. You should have a working Asterisk system before trying to setup IVR in Asterisk. If you’re new and would like to install Asterisk, you can use our tutorial based on CentOS below:
The IVR in Asterisk design shown here is for a small campus with the following offices as sample:
You can modify all configurations to suit your use case. SIP users added to sip.conf file are as below.
The next step is to have the context ready to rock. The context is given below:
[moi-incoming]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered IVR menu)
same => n,Answer()
same => n,Set(TIMEOUT(digit)=2) ; this sets the inter-digit timer
same => n,Wait(2) ; wait two second to establish audio
; During job hours, jump to moi-ivr context.
; During closed hours, jumpt to offices-closed.
same => n,GotoIfTime(9:00-16:00,mon-fri,*,*?moi-ivr,s,1:offices-closed)
same => n,GotoIfTime(9:00-12:00,sat,*,*?moi-ivr,s,1:offices-closed)
[offices-closed]
exten =>s,1,Answer()
same => n,wait(2)
same => Background(basic-pbx-ivr-main)
same => n,Hangup()
[moi-ivr]
exten =>s,1,Answer()
same => n,wait(2)
same => n,Set(TIMEOUT(digit)=10) ; ; this sets the inter-digit timer
same => n,Set(TIMEOUT(response)=10)
same => n,Background(basic-pbx-ivr-main)
same => n,WaitExten()
same => n,Background(silence/5)
; 1 to talk to reception ;101
; 2 to talk to finance office ; 102
; 3 to talk to dvc office ;103
; 4 to talk to security office ; 104
; 5 to talk to ICT office ;105
; 6 to talk to schools office ; 106
; 7 to talk to accommodation office ;107
exten => 1,1,Goto(ivr-customercare,s,1)
exten => 2,1,Goto(ivr-finance,s,1)
exten => 3,1,Goto(ivr-dvc,s,1)
exten => 4,1,Goto(ivr-security,s,1)
exten => 5,1,Goto(ivr-ict,s,1)
exten => 6,1,Goto(ivr-schools,s,1)
exten => 7,1,Goto(ivr-accomodation,s,1)
;; 'i' extension that is used for invalid extensions, i e, non-existing extensions dialled by clients.
exten => i,1,Playback(option-is-invalid)
same => n,Goto(moi-ivr)
;; Timeout extension
exten => t,1,Playback(still-there)
exten => t,Goto(moi-ivr,s,5)
;; define extensions for IVR menu
[ivr-reception]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered Customer care support center)
same => n,Answer()
same => n,Dial(SIP/101,10,r)
same => n,Hangup()
same => n,Playback(unavail)
same => n,Hangup()
[ivr-finance]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered Customercare support center)
same => n,Answer()
same => n,Dial(SIP/102,10,r)
same => n,Hangup()
same => n,Playback(unavail)
same => n,Hangup()
[ivr-dvc]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered Customercare support center)
same => n,Answer()
same => n,Dial(SIP/103,10,r)
same => n,Hangup()
same => n,Playback(unavail)
same => n,Hangup()
[ivr-security]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered Customercare support center)
same => n,Answer()
same => n,Dial(SIP/104,10,r)
same => n,Hangup()
same => n,Playback(unavail)
same => n,Hangup()
[ivr-ict]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered Customercare support center)
same => n,Answer()
same => n,Dial(SIP/105,10,r)
same => n,Hangup()
same => n,Playback(unavail)
same => n,Hangup()
[ivr-schools]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered Customercare support center)
same => n,Answer()
same => n,Dial(SIP/106,10,r)
same => n,Hangup()
same => n,Playback(unavail)
same => n,Hangup()
[ivr-accommodation]
exten =>s,1,Verbose(1, Caller ${CALLERID(all)} has entered Customercare support center)
same => n,Answer()
same => n,Dial(SIP/107,10,r)
same => n,Hangup()
same => n,Playback(unavail)
same => n,Hangup()
Now whenever a person dial 101 and make a call, its processing will be done on IVR context. Key point to note is that all extension numbers used on IVR must be registered for a call to be routed.
If you have a separate call routing logic on extensions.conf for PSTN incoming calls, just include IVR context in it.