How to use AGI Script in Asterisk on Oracle Linux 9.3
To Use AGI Script In Asterisk On Oracle Linux 9.3
Introduction:
The Asterisk Gateway Interface (AGI) serves as a connection point between the Asterisk dialplan and an external program seeking to interact with a channel within the dialplan. This interface typically operates in a synchronous manner, meaning that actions performed on a channel from an AGI block will not conclude until the action has been fully executed.
Procedure:
Step 1: Check the OS version by using the below command
[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.3"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.3"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.3"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:3:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.3
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.3
Step 2: I have already installed Asterisk on my Oracle Linux machine, Now I am going to check the status of the Asterisk by using the below command
[root@linuxhelp ~]# systemctl status asterisk.service
● asterisk.service - LSB: Asterisk PBX
Loaded: loaded (/etc/rc.d/init.d/asterisk; generated)
Active: active (running) since Fri 2024-05-31 13:45:37 IST; 7min ago
Docs: man:systemd-sysv-generator(8)
Process: 6338 ExecStart=/etc/rc.d/init.d/asterisk start (code=exited, status=0/SUCCESS)
Main PID: 6367 (asterisk)
Tasks: 38 (limit: 21739)
Memory: 37.2M
CPU: 4.392s
CGroup: /system.slice/asterisk.service
├─6365 /bin/sh /usr/sbin/safe_asterisk
└─6367 /usr/sbin/asterisk -f -vvvg -c
May 31 13:45:37 linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
May 31 13:45:37 linuxhelp asterisk[6338]: Starting asterisk:
May 31 13:45:37 linuxhelp systemd[1]: asterisk.service: Can't open PID file /run/asterisk/asterisk.pid (yet?) after start: Operation not permitted
May 31 13:45:37 linuxhelp systemd[1]: asterisk.service: Supervising process 6367 which is not our child. We'll most likely not notice when it exit>
May 31 13:45:37 linuxhelp systemd[1]: Started LSB: Asterisk PBX.
Step 3: Now change the directory to Asterisk default AGI directory by using the below command
[root@linuxhelp ~]# cd /var/lib/asterisk/agi-bin/
Step 4: List the directory by using the below command
[root@linuxhelp agi-bin]# ll
total 0
Step 5: Create a new file using vim editor by using the below command
[root@linuxhelp agi-bin]# vim demoagi
Add those following command
#!/usr/bin/bash
echo "SET VARIABLE rep $1"
echo "SET VARIABLE exten $2"
Step 6: Now give the execute permission to the file by using the below command
[root@linuxhelp agi-bin]# chmod +x demoagi
Step 7: Change the directory to the asterisk configuration directory by using the below command
[root@linuxhelp agi-bin]# cd /etc/asterisk/
Step 8: Now edit the extensions.conf file to change the dialplan by using the below command
[root@linuxhelp asterisk]# vim extensions.conf
Add those Following Command
[internal]
exten => _XXX,1,AGI(demoagi,3,${EXTEN})
exten => _XXX,n,NoOp(Dialing Extension is =============== ${exten} and the repeat is ========== ${rep})
exten => _XXX,n,Set(repeat=${rep})
exten => _XXX,n(repeat),Playback(hello)
exten => _XXX,n,Set(repeat=$[ ${repeat} - 1 ])
exten => _XXX,n,GotoIf($[ ${repeat} > 0]?repeat:continue)
exten => _XXX,n(continue),Dial(PJSIP/${exten})
Step 9: Login to the Asterisk CLI mode by using the below command
root@linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvvvvvv
Asterisk 20.5.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.5.0 currently running on linuxhelp (pid = 8900)
linuxhelp*CLI>
Step 10: After the changes in the extensions.conf file, need to reload the dialplan by using the below command
linuxhelp*CLI> dialplan reload
Dialplan reloaded.
-- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
-- Time to scan old dialplan and merge leftovers back into the new: 0.000212 sec
-- Time to restore hints and swap in new dialplan: 0.000006 sec
-- Time to delete the old dialplan: 0.000054 sec
-- Total time merge_contexts_delete: 0.000272 sec
-- pbx_config successfully loaded 22 contexts (enable debug for details).
Step 11: Now try to make a call by using the Zoiper and microsip software
Step 12: Now make call from 167 to 168
Output:
Executing [168@internal:1] AGI("PJSIP/167-00000000", "demoagi,3,168") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/demoagi
-- <PJSIP/167-00000000>AGI Script demoagi completed, returning 0
-- Executing [168@internal:2] NoOp("PJSIP/167-00000000", "Dialing Extension is =============== 168 and the repeat is ========== 3") in new stack
-- Executing [168@internal:3] Set("PJSIP/167-00000000", "repeat=3") in new stack
-- Executing [168@internal:4] Playback("PJSIP/167-00000000", "hello") in new stack
> 0x7f1a88011aa0 -- Strict RTP learning after remote address set to: 192.168.6.101:8000
> 0x7f1a88011aa0 -- Strict RTP switching to RTP target address 192.168.6.101:8000 as source
-- <PJSIP/167-00000000> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:5] Set("PJSIP/167-00000000", "repeat=2") in new stack
-- Executing [168@internal:6] GotoIf("PJSIP/167-00000000", "1?repeat:continue") in new stack
-- Goto (internal,168,4)
-- Executing [168@internal:4] Playback("PJSIP/167-00000000", "hello") in new stack
-- <PJSIP/167-00000000> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:5] Set("PJSIP/167-00000000", "repeat=1") in new stack
-- Executing [168@internal:6] GotoIf("PJSIP/167-00000000", "1?repeat:continue") in new stack
-- Goto (internal,168,4)
-- Executing [168@internal:4] Playback("PJSIP/167-00000000", "hello") in new stack
-- <PJSIP/167-00000000> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:5] Set("PJSIP/167-00000000", "repeat=0") in new stack
-- Executing [168@internal:6] GotoIf("PJSIP/167-00000000", "0?repeat:continue") in new stack
-- Goto (internal,168,7)
-- Executing [168@internal:7] Dial("PJSIP/167-00000000", "PJSIP/168") in new stack
-- Called PJSIP/168
-- PJSIP/168-00000001 is ringing
> 0x7f1a88011aa0 -- Strict RTP learning complete - Locking on source address 192.168.6.101:8000
== Everyone is busy/congested at this time (1:1/0/0)
-- Auto fallthrough, channel 'PJSIP/167-00000000' status is 'BUSY'
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to use AGI Script on Asterisk on Oracle Linux 9.3. Your feedback is much welcome.
Comments ( 0 )
No comments available