DEV Community


Posted on

Basic IVR with Asterisk

Weekly sharing

Hi everyone, I am Ekim, a fresh Bootcamp graduate and an IT helper (I don't dare to call myself a programmer yet). Every Friday, I will share some of the work that I've done over the last week in a bid to get feedbacks from you guys and record my journey to become a programmer.


Asterisk Manager with JavaScript


Today, I would like to share how we could make a simple interactive voice response (IVR). I know you might have had some horrible experiences with that, but it would be a weird but fun experience when you hear your voice on the phone talking to you.

What is Interactive Voice Response (IVR) menu?

  • An IVR menu is a list of options that are presented to an inbound caller which prompts them to make a selection, thus qualifying the call and directing it to the most appropriate contact.

Recording our own audio track through Asterisk for IVR

  • If you have read my previous posts, you would know that the codecs that telephony supports are limited.

  • Even if you have recorded a very good quality audio track, you still need to convert it into the format that our phones support.

  • To save time, I am not going to go through the ffmpeg part again. Instead, I am going to record all the IVR audio track through the Record dialplan application.

  • In pjsip.conf

    type = transport
    protocol = udp
    bind =

    allow = !all, ulaw, alaw     

    type = auth              
    auth_type = userpass     
    type = aor
    max_contacts = 1         

    callerid = 7000 <7000>   

    password = 7000
    username = 7000

    mailboxes = 7000@main

    callerid = 7100 <7100>

    password = 7100
    username = 7100

    mailboxes = 7100@main
Enter fullscreen mode Exit fullscreen mode
  • In extensions.conf
exten = *555,1,NoOp(recording)
same = n,Answer
same = n,Record(record/greeting.wav)
same = n,Playback(vm-received)
same = n,Playback(en/digits/1)
same = n,Record(record/press1.wav)
same = n,Playback(vm-received)
same = n,Playback(en/digits/2)
same = n,Record(record/press2.wav)
same = n,Playback(vm-received)
same = n,Playback(en/digits/3)
same = n,Playback(vm-last)
same = n,Record(record/wrong-key.wav)
same = n,Playback(vm-received)
same = n,Playback(en/digits/4)
same = n,Hangup

;exten = _7X00,1,NoOp(Call for ${EXTEN})    
;same = n,Dial(PJSIP/${EXTEN})      
;same = n,Hangup    

exten = 8888,1,NoOp(Call IVR)
same = n,Goto(ivr,s,1)

exten = s,1,NoOp(You are in IVR now)
same = n,Answer                     ; here is the start of the SIP protocol
same = n(play),Playback(record/greeting)
same = n,WaitExten(10)              ; wait 10 seconds for the caller to press key

exten = 1,1,NoOp(Pressed 1)
same = n,Playback(record/press1)
same = n,Goto(s,play)               ; go back to 'n(play),Playback(record/greeting)'

exten = 2,1,NoOp(Pressed 2)
same = n,Playback(record/press2)
same = n,Goto(s,play)

exten = i,1,NoOp(unknown key)       ; handle invalid keys --> when keys other than 1 and 2 are pressed
same = n,Playback(record/wrong-key)
same = n,Goto(s,play)

exten = t,1,NoOp(Waited too long for exten)     ; handle WaitExten timeout
same = n,Goto(s,play)
Enter fullscreen mode Exit fullscreen mode


  • First of all, let's record all the necessary navigation menu tracks.
  • I have set in the dialplan that when we call *555 , we will start recording each audio file one by one. - When you hear the first 'beep' sound, it is for the recording of the greeting. - For example, "thanks for calling, English, press 1; Deutsch, press 2". - When you finish each recording, remember to press # to save it.
  • If successful, you will hear the number of recording received.
    • If you finished one recording, you will hear "received 1"
  • When you hear "last", that means you are going to record the last audio.
  • Here is the sequence of the recording sections

    1. greeting
      1. the navigation after pressing 1
      2. the navigation after pressing 2
      3. the navigation when wrong key is pressed
  • To go into the IVR, dial 8888 and it will start the IVR menu.


Now, you have just made yourself an IVR menu. If you follow tight, you would realize that the whole IVR is a loop. You could feel free to add the Hangup dialplan application wherever you like. One thing I would like to stress here is that this IVR structure is a very basic one as things are repetitive and could be refactorized in another way. A more advanced one might be introduced some time later (I hope ... ) with the use of database and AGI (Asterisk Gateway Interface). That's all for today. See you next time.

Top comments (0)