AMP AMP

How to create a basic Asterisk IVR on Debian 12

To Create A Basic Asterisk IVR On Debian 12

Introduction

Asterisk includes a wealth of functions that make it a powerful IVR platform: audio playback and recording, digit collection, database and web service access, calendar integration, and optional speech recognition and synthesis.

Procedure Steps

Step 1: Check the OS version by using the below command.

root@linuxhelp:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL=https://bugs.debian.org/

Step 2: Goto the following location by using the below command.

root@linuxhelp:~# cd /etc/asterisk/

Step 3: Open and Edit the extensions.conf file by using the below command.

root@linuxhelp:/etc/asterisk# vim extensions.conf
[internal]

exten => 110,1,NoOp(Calling ${EXTEN} From Caller ${CALLERID})
same=> n,Answer()
same=> n,Playback(for-service&press-1&for-sales&press-2)
same=> n,Read(VAR,,,,,4)
same=> n,GotoIf($[ "${VAR}" = "1" ]?111,1)
same=> n,GotoIf($[ "${VAR}" = "2" ]?112,1:110,1)

exten => 111,1,NoOp(For Service Calling From ${CALLERID})
same=> n,Answer()
same=> n,SayDigits(1)
same=> n,Playback(for-service)
same=> n,Dial(PJSIP/111,10)
same=> n,Hangup()

exten => 112,1,NoOp(For Sales Calling From ${CALLERID})
same=> n,Answer()
same=> n,SayDigits(2)
same=> n,Playback(for-sales)
same=> n,Dial(PJSIP/112,10)
same=> n,Hangup()

Step 4: Login to the asterisk console by using the below command.

root@linuxhelp:/etc/asterisk# asterisk -rvvvvvvvvvvvvvvvvvvv
Asterisk 20.4.0, Copyright (C) 1999 - 2022, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 20.4.0 currently running on linuxhelp (pid = 1294)
linuxhelp*CLI>

Step 5: Reload the dialplan by using following command.

linuxhelp*CLI> dialplan reload
Dialplan reloaded.
    -- Time to scan old dialplan and merge leftovers back into the new: 0.000004 sec
    -- Time to restore hints and swap in new dialplan: 0.000003 sec
    -- Time to delete the old dialplan: 0.000004 sec
    -- Total time merge_contexts_delete: 0.000011 sec
    -- pbx_config successfully loaded 1 contexts (enable debug for details).

Step 6: Make the call to check service call from IVR menu by using the below command.

linuxhelp*CLI> 
    -- Executing [110@internal:1] NoOp("PJSIP/112-00000006", "Calling 110 From Caller ") in new stack
    -- Executing [110@internal:2] Answer("PJSIP/112-00000006", "") in new stack
       > 0x7f5654010aa0 -- Strict RTP learning after remote address set to: 192.168.6.107:4010
    -- Executing [110@internal:3] Playback("PJSIP/112-00000006", "for-service&press-1&for-sales&press-2") in new stack
    -- <PJSIP/112-00000006> Playing 'for-service.ulaw' (language 'en')
       > 0x7f5654010aa0 -- Strict RTP switching to RTP target address 192.168.6.107:4010 as source
    -- <PJSIP/112-00000006> Playing 'press-1.ulaw' (language 'en')
    -- <PJSIP/112-00000006> Playing 'for-sales.ulaw' (language 'en')
    -- <PJSIP/112-00000006> Playing 'press-2.ulaw' (language 'en')
    -- Executing [110@internal:4] Read("PJSIP/112-00000006", "VAR,,,,,4") in new stack
       > 0x7f5654010aa0 -- Strict RTP learning complete - Locking on source address 192.168.6.107:4010
    -- User entered '1'
    -- Executing [110@internal:5] GotoIf("PJSIP/112-00000006", "1?111,1") in new stack
    -- Goto (internal,111,1)
    -- Executing [111@internal:1] NoOp("PJSIP/112-00000006", "For Service Calling From ") in new stack
    -- Executing [111@internal:2] Answer("PJSIP/112-00000006", "") in new stack
    -- Executing [111@internal:3] SayDigits("PJSIP/112-00000006", "1") in new stack
    -- <PJSIP/112-00000006> Playing 'digits/1.ulaw' (language 'en')
    -- Executing [111@internal:4] Playback("PJSIP/112-00000006", "for-service") in new stack
    -- <PJSIP/112-00000006> Playing 'for-service.ulaw' (language 'en')
    -- Executing [111@internal:5] Dial("PJSIP/112-00000006", "PJSIP/111,10") in new stack
    -- Called PJSIP/111
    -- PJSIP/111-00000007 is ringing
  == Everyone is busy/congested at this time (1:1/0/0)
    -- Executing [111@internal:6] Hangup("PJSIP/112-00000006", "") in new stack
  == Spawn extension (internal, 111, 6) exited non-zero on 'PJSIP/112-00000006'

Step 7: Make the call to check sales call from ivr menu by using the below command.

-- Executing [110@internal:1] NoOp("PJSIP/112-00000008", "Calling 110 From Caller ") in new stack
  -- Executing [110@internal:2] Answer("PJSIP/112-00000008", "") in new stack
     > 0x7f5654010aa0 -- Strict RTP learning after remote address set to: 192.168.6.107:4012
  -- Executing [110@internal:3] Playback("PJSIP/112-00000008", "for-service&press-1&for-sales&press-2") in new stack
  -- <PJSIP/112-00000008> Playing 'for-service.ulaw' (language 'en')
     > 0x7f5654010aa0 -- Strict RTP switching to RTP target address 192.168.6.107:4012 as source
  -- <PJSIP/112-00000008> Playing 'press-1.ulaw' (language 'en')
  -- <PJSIP/112-00000008> Playing 'for-sales.ulaw' (language 'en')
  -- <PJSIP/112-00000008> Playing 'press-2.ulaw' (language 'en')
  -- Executing [110@internal:4] Read("PJSIP/112-00000008", "VAR,,,,,4") in new stack
     > 0x7f5654010aa0 -- Strict RTP learning complete - Locking on source address 192.168.6.107:4012
  -- User entered '2'
  -- Executing [110@internal:5] GotoIf("PJSIP/112-00000008", "0?111,1") in new stack
  -- Executing [110@internal:6] GotoIf("PJSIP/112-00000008", "1?112,1:110,1") in new stack
  -- Goto (internal,112,1)
  -- Executing [112@internal:1] NoOp("PJSIP/112-00000008", "For Sales Calling From ") in new stack
  -- Executing [112@internal:2] Answer("PJSIP/112-00000008", "") in new stack
  -- Executing [112@internal:3] SayDigits("PJSIP/112-00000008", "2") in new stack
  -- <PJSIP/112-00000008> Playing 'digits/2.ulaw' (language 'en')
  -- Executing [112@internal:4] Playback("PJSIP/112-00000008", "for-sales") in new stack
  -- <PJSIP/112-00000008> Playing 'for-sales.ulaw' (language 'en')
  -- Executing [112@internal:5] Dial("PJSIP/112-00000008", "PJSIP/112,10") in new stack
  -- Called PJSIP/112
  -- PJSIP/112-00000009 is ringing
== Everyone is busy/congested at this time (1:1/0/0)
  -- Executing [112@internal:6] Hangup("PJSIP/112-00000008", "") in new stack
== Spawn extension (internal, 112, 6) exited non-zero on 'PJSIP/112-00000008'

Step 8: Make the call to check ivr menu by using the below command.

-- Executing [110@internal:1] NoOp("PJSIP/112-0000000a", "Calling 110 From Caller ") in new stack
 -- Executing [110@internal:2] Answer("PJSIP/112-0000000a", "") in new stack
    > 0x7f5654010aa0 -- Strict RTP learning after remote address set to: 192.168.6.107:4016
 -- Executing [110@internal:3] Playback("PJSIP/112-0000000a", "for-service&press-1&for-sales&press-2") in new stack
 -- <PJSIP/112-0000000a> Playing 'for-service.ulaw' (language 'en')
    > 0x7f5654010aa0 -- Strict RTP switching to RTP target address 192.168.6.107:4016 as source
 -- <PJSIP/112-0000000a> Playing 'press-1.ulaw' (language 'en')
 -- <PJSIP/112-0000000a> Playing 'for-sales.ulaw' (language 'en')
 -- <PJSIP/112-0000000a> Playing 'press-2.ulaw' (language 'en')
 -- Executing [110@internal:4] Read("PJSIP/112-0000000a", "VAR,,,,,4") in new stack
    > 0x7f5654010aa0 -- Strict RTP learning complete - Locking on source address 192.168.6.107:4016
 -- User entered '3'
 -- Executing [110@internal:5] GotoIf("PJSIP/112-0000000a", "0?111,1") in new stack
 -- Executing [110@internal:6] GotoIf("PJSIP/112-0000000a", "0?112,1:110,1") in new stack
 -- Goto (internal,110,1)
 -- Executing [110@internal:1] NoOp("PJSIP/112-0000000a", "Calling 110 From Caller ") in new stack
 -- Executing [110@internal:2] Answer("PJSIP/112-0000000a", "") in new stack
 -- Executing [110@internal:3] Playback("PJSIP/112-0000000a", "for-service&press-1&for-sales&press-2") in new stack
 -- <PJSIP/112-0000000a> Playing 'for-service.ulaw' (language 'en')
 -- <PJSIP/112-0000000a> Playing 'press-1.ulaw' (language 'en')
 -- <PJSIP/112-0000000a> Playing 'for-sales.ulaw' (language 'en')
 -- <PJSIP/112-0000000a> Playing 'press-2.ulaw' (language 'en')
 -- Executing [110@internal:4] Read("PJSIP/112-0000000a", "VAR,,,,,4") in new stack
 -- User entered nothing.
 -- Executing [110@internal:5] GotoIf("PJSIP/112-0000000a", "0?111,1") in new stack
 -- Executing [110@internal:6] GotoIf("PJSIP/112-0000000a", "0?112,1:110,1") in new stack
 -- Goto (internal,110,1)
 -- Executing [110@internal:1] NoOp("PJSIP/112-0000000a", "Calling 110 From Caller ") in new stack
 -- Executing [110@internal:2] Answer("PJSIP/112-0000000a", "") in new stack
 -- Executing [110@internal:3] Playback("PJSIP/112-0000000a", "for-service&press-1&for-sales&press-2") in new stack
 -- <PJSIP/112-0000000a> Playing 'for-service.ulaw' (language 'en')
 -- <PJSIP/112-0000000a> Playing 'press-1.ulaw' (language 'en')
 -- <PJSIP/112-0000000a> Playing 'for-sales.ulaw' (language 'en')
 -- <PJSIP/112-0000000a> Playing 'press-2.ulaw' (language 'en')
 -- Executing [110@internal:4] Read("PJSIP/112-0000000a", "VAR,,,,,4") in new stack
 -- User disconnected

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to create a basic Asterisk IVR on Debian 12. Your feedback is much welcome.

FAQ
Q
How do I secure my IVR system and prevent unauthorized access?
A
Security is vital for any phone system, especially when dealing with sensitive information. Asterisk offers password protection, access control lists, and encryption options to secure your IVR environment.
Q
Can I use speech recognition with my IVR for hands-free interaction?
A
Yes, Asterisk can integrate with speech recognition engines like Google Speech-to-Text or Sphinx. This allows callers to navigate options or provide information using their voice.
Q
How do I handle situations where callers enter invalid input or don't respond?
A
Error handling and retries are crucial for a smooth IVR experience. Asterisk offers tools like GotoIf, Wait, and Playback to handle invalid inputs, provide error messages, and offer repeat options.
Q
Can I integrate my IVR with a database to access or update information?
A
Yes, Asterisk can connect to databases through ODBC or DBI modules. This allows storing and retrieving information like customer details or dynamic menu options during the IVR interaction.
Q
How do I create a basic IVR menu with options for callers to choose from?
A
This is a common starting point for many Asterisk IVR setups. It involves using the Read application to capture user input and Goto or GotoIf commands to direct calls based on selected options.