How to use Asterisk AGI Script on Debian 12
To Use Asterisk AGI On Debian 12
Introduction:
The Asterisk Gateway Protocol (AGI) is the protocol used by the Asterisk server as its interface for telephony applications. AGI is just a way that allows you (as a software developer) to easily make telephony applications that asterisk will run someway along the dialplan. Through AGI, you can read input from the user, play sound files, control the call and its flow, and pretty much everything needed to make a successful IVR (Interactive Voice Response) in virtually any programming language.
Procedure:
Step 1: Check the OS version by using following 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: Check the Asterisk version by using following command.
root@linuxhelp:~# asterisk -V
Asterisk 20.4.0
Step 3: Open and make the AGI script by using following command.
root@linuxhelp:~# vim agi
Step 4: Make the executable permission by using following command.
root@linuxhelp:~# chmod +x agi
Step 5: Long list files to check executable permission by using following command.
root@linuxhelp:~# ls -la
total 27620
drwx------ 8 root root 4096 Jan 23 02:47 .
drwxr-xr-x 19 root root 4096 Dec 25 20:42 ..
-rwxr-xr-x 1 root root 91 Jan 23 02:47 agi
Step 6: Go to the following location by using following command.
root@linuxhelp:~# cd /etc/asterisk
Step 7: Open the extensions.conf file and make the dialplan configuration using AGI application by using following command.
root@linuxhelp:/etc/asterisk# vim extensions.conf
[internal]
exten => 110,1,NoOp(Extension 110)
same=>n,Answer()
same=>n,NoOP()
same=>n,AGI(/root/agi)
same=>n,Playback(${agi_sound1})
same=>n,Dial(PJSIP/110, 10)
same=>n,Playback(hangup)
same=>n,Hangup()
exten =>111,1,NoOp(Extension 111)
same=>n,Answer()
same=>n,AGI(/root/agi)
same=>n,Playback(${agi_sound2})
same=>n,Hangup()
exten=>112,1,NoOp(Extension 112)
same=>n,Answer()
same=>n,Dial(PJSIP/112,10)
same=>n,Playback(welcome)
same=>n,Hangup()
Step 8: Login to the Asterisk console by using following command.
root@linuxhelp:~# asterisk -rvvvvvvvvvvvvv
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 = 1259)
linuxhelp*CLI>
Step 9: Reload the dialplan configuration by using following command.
linuxhelp*CLI> dialplan reload
Dialplan reloaded.
-- Time to scan old dialplan and merge leftovers back into the new: 0.000021 sec
-- Time to restore hints and swap in new dialplan: 0.000003 sec
-- Time to delete the old dialplan: 0.000006 sec
-- Total time merge_contexts_delete: 0.000030 sec
-- pbx_config successfully loaded 1 contexts (enable debug for details).
linuxhelp*CLI>
Step 10: Make the call to check the AGI by using microsip application as shown in below image.
-- Executing [110@internal:1] NoOp("PJSIP/112-0000001c", "Extension 110") in new stack
-- Executing [110@internal:2] Answer("PJSIP/112-0000001c", "") in new stack
> 0x7fbfa802dc00 -- Strict RTP learning after remote address set to: 192.168.6.107:4048
-- Executing [110@internal:3] NoOp("PJSIP/112-0000001c", "") in new stack
-- Executing [110@internal:4] AGI("PJSIP/112-0000001c", "/root/agi") in new stack
-- Launched AGI Script /root/agi
-- <PJSIP/112-0000001c>AGI Script /root/agi completed, returning 0
-- Executing [110@internal:5] Playback("PJSIP/112-0000001c", "welcome") in new stack
-- <PJSIP/112-0000001c> Playing 'welcome.ulaw' (language 'en')
> 0x7fbfa802dc00 -- Strict RTP switching to RTP target address 192.168.6.107:4048 as source
-- Executing [110@internal:6] Dial("PJSIP/112-0000001c", "PJSIP/110, 10") in new stack
-- Called PJSIP/110
-- PJSIP/110-0000001d is ringing
> 0x7fbfa802dc00 -- Strict RTP learning complete - Locking on source address 192.168.6.107:4048
== Everyone is busy/congested at this time (1:1/0/0)
-- Executing [110@internal:7] Playback("PJSIP/112-0000001c", "hangup") in new stack
[Jan 23 03:05:25] WARNING[12986][C-00000017]: file.c:824 ast_openstream_full: File hangup does not exist in any format
[Jan 23 03:05:25] WARNING[12986][C-00000017]: file.c:1303 ast_streamfile: Unable to open hangup (format (ulaw)): No such file or directory
[Jan 23 03:05:25] WARNING[12986][C-00000017]: app_playback.c:512 playback_exec: Playback failed on PJSIP/112-0000001c for hangup
-- Executing [110@internal:8] Hangup("PJSIP/112-0000001c", "") in new stack
== Spawn extension (internal, 110, 8) exited non-zero on 'PJSIP/112-0000001c'
Step 11: Make the call to check the AGI by using microsip application as shown in below image.
-- Executing [111@internal:1] NoOp("PJSIP/112-0000001e", "Extension 111") in new stack
-- Executing [111@internal:2] Answer("PJSIP/112-0000001e", "") in new stack
> 0x7fbfa802dc00 -- Strict RTP learning after remote address set to: 192.168.6.107:4050
-- Executing [111@internal:3] AGI("PJSIP/112-0000001e", "/root/agi") in new stack
-- Launched AGI Script /root/agi
> 0x7fbfa802dc00 -- Strict RTP switching to RTP target address 192.168.6.107:4050 as source
-- <PJSIP/112-0000001e>AGI Script /root/agi completed, returning 0
-- Executing [111@internal:4] Playback("PJSIP/112-0000001e", "hangup") in new stack
[Jan 23 03:06:27] WARNING[13049][C-00000018]: file.c:824 ast_openstream_full: File hangup does not exist in any format
[Jan 23 03:06:27] WARNING[13049][C-00000018]: file.c:1303 ast_streamfile: Unable to open hangup (format (ulaw)): No such file or directory
[Jan 23 03:06:27] WARNING[13049][C-00000018]: app_playback.c:512 playback_exec: Playback failed on PJSIP/112-0000001e for hangup
-- Executing [111@internal:5] Hangup("PJSIP/112-0000001e", "") in new stack
== Spawn extension (internal, 111, 5) exited non-zero on 'PJSIP/112-0000001e'
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to use Asterisk AGI on Debian 12. Your feedback is much welcome.
Comments ( 0 )
No comments available