• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to use Asterisk AGI Script on Debian 12

  • 00:51 cat /etc/os-release
  • 01:05 asterisk -V
  • 01:18 vim agi
  • 02:11 chmod +x agi
  • 02:19 ls -la
  • 02:36 cd /etc/asterisk
  • 02:53 vim extensions.conf
  • 04:43 asterisk -rvvvvvvvvvvvvv
  • 04:51 dialplan reload
{{postValue.id}}

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.

snap 1

		-- 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.

snap 2

-- 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.

Tags:
michael
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is Asterisk AGI?

A

Asterisk AGI (Asterisk Gateway Interface) is a protocol that enables external programs to interact with the Asterisk telephony software. It allows for the execution of custom scripts or applications during call processing.

Q

How does Asterisk AGI work?

A

Asterisk AGI works by establishing a connection between Asterisk and an external program or script using a defined protocol. When configured, Asterisk can execute AGI scripts at various points during call processing, passing call-related information to the external program and receiving instructions in return.

Q

What programming languages can I use to write AGI scripts?

A

AGI scripts can be written in various programming languages such as Perl, Python, PHP, Ruby, or even compiled languages like C or C++. As long as the language can establish communication over stdin and stdout, it can be used for AGI scripting.

Q

What can AGI scripts do?

A

AGI scripts can perform a wide range of tasks including call routing, IVR (Interactive Voice Response) systems, call recording, database integration, speech recognition, text-to-speech conversion, and more. Essentially, AGI scripts allow for custom call handling and integration with external systems.

Q

How do I configure Asterisk to use AGI scripts?

A

To configure Asterisk to use AGI scripts, you typically define the AGI script's path and options in the Asterisk dial plan. This involves specifying an AGI command followed by the path to the script and any required parameters.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Gibbson ?
How do i run both nginx and apache in same instance on centos

Hi...,

my server is based centos operating system and my webserver is already running on Apache.... i need to run both apache and nginx on same instance ... please help me to implement this concept...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.