How to use GoTo and GotoIf Application on Asterisk on Oracle Linux 9.3
- 00:52 cat /etc/os-release
- 01:05 systemctl status asterisk.service
- 01:23 cd /etc/asterisk/
- 01:36 vim extensions.conf
- 01:58 asterisk -rvvvvvvvvvvvvvvvvvvvvvv
- 02:06 dialplan reload
- 02:50 vim extensions.conf
- 03:11 asterisk -rvvvvvvvvvvvvvvvvvvv
- 03:19 dialplan reload
- 04:07 vim extensions.conf
- 04:28 asterisk -rvvvvvvvvvvvvvvv
- 04:41 Dialplan reload
To Use GoTo And GotoIf Application On Asterisk On Oracle Linux 9.3
Introduction:
GoTo - this application allows you to jump to another extension, another context, or another priority. The GotoIf( ) Application - An empty string and the number 0 evaluated as false. Anything else is evaluated as true. GotoIf is a conditional goto command. Go to label1 if the condition is true or to the next step (or label2 if defined) if the condition is false.
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: 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 Mon 2024-02-19 04:02:05 IST; 1 month 2 days ago
Docs: man:systemd-sysv-generator(8)
Process: 1001 ExecStart=/etc/rc.d/init.d/asterisk start (code=exited, status=0/SUCCESS)
Main PID: 1062
Tasks: 37 (limit: 21739)
Memory: 63.3M
CPU: 7.852s
CGroup: /system.slice/asterisk.service
├─1056 /bin/sh /usr/sbin/safe_asterisk
└─5831 /usr/sbin/asterisk -f -vvvg -c
Feb 19 04:02:05 linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
Feb 19 04:02:05 linuxhelp asterisk[1001]: Starting asterisk:
Feb 19 04:02:05 linuxhelp systemd[1]: asterisk.service: Can't open PID file /run/asterisk/asterisk.pid (yet?) after start: Operation not permitted
Feb 19 04:02:05 linuxhelp systemd[1]: asterisk.service: Supervising process 1062 which is not our child. We'll most likely not notice when it exits.
Feb 19 04:02:05 linuxhelp systemd[1]: Started LSB: Asterisk PBX.
Step 3: Move to the Asterisk directory by using the below command
[root@linuxhelp ~]# cd /etc/asterisk/
[root@linuxhelp asterisk]#
Step 4: Edit the extensions.conf file by using the below command
[root@linuxhelp asterisk]# vim extensions.conf
Add those following lines
[internal]
exten => _XXX,1,NoOp(Call started for ${EXTEN})
exten => _XXX,2,Goto(5)
exten => _XXX,3,Hangup()
exten => _XXX,4,Playback(hello)
exten => _XXX,5,Dial(PJSIP/168)
Step 5: Now Login to the asterisk CLI mode by using the below command
[root@linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvvvvvvvvv
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 = 5831)
linuxhelp*CLI>
Step 6: Reload the dialplan by using the below 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.000007 sec
-- Time to delete the old dialplan: 0.000003 sec
-- Total time merge_contexts_delete: 0.000014 sec
-- pbx_config successfully loaded 1 contexts (enable debug for details).
linuxhelp*CLI>
Output:
Executing [167@internal:1] NoOp("PJSIP/168-00000012", "Call started for 167") in new stack
-- Executing [167@internal:2] Goto("PJSIP/168-00000012", "5") in new stack
-- Goto (internal,167,5)
-- Executing [167@internal:5] Dial("PJSIP/168-00000012", "PJSIP/168") in new stack
-- Called PJSIP/168
-- PJSIP/168-00000013 is ringing
== Everyone is busy/congested at this time (1:1/0/0)
-- Auto fallthrough, channel 'PJSIP/168-00000012' status is 'BUSY'
linuxhelp*CLI>
Step 7: Edit the extensions.conf file to use Goto Application with alternative priority by using the below command.
[root@linuxhelp asterisk]# vim extensions.conf
Add the following lines
[internal]
exten => _XXX,1,NoOp(Call started for ${EXTEN})
exten => _XXX,2,Goto(4)
exten => _XXX,3,Hangup()
exten => _XXX,4,Playback(hello)
exten => _XXX,5,Dial(PJSIP/168)
Step 8: Login to the Asterisk CLI by using the below command.
[root@linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvvvvvv
Asterisk 20.3.1, 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.3.1 currently running on linuxhelp1 (pid = 1427)
linuxhelp*CLI>
Step 9: Reload the dialplan by using the below 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.000007 sec
-- Time to delete the old dialplan: 0.000005 sec
-- Total time merge_contexts_delete: 0.000016 sec
-- pbx_config successfully loaded 1 contexts (enable debug for details).
Output
-- Executing [168@internal:1] NoOp("PJSIP/167-00000014", "Call started for 168") in new stack
-- Executing [168@internal:2] Goto("PJSIP/167-00000014", "4") in new stack
-- Goto (internal,168,4)
-- Executing [168@internal:4] Playback("PJSIP/167-00000014", "hello") in new stack
> 0x7f740402a2e0 -- Strict RTP learning after remote address set to: 192.168.6.102:8000
> 0x7f740402a2e0 -- Strict RTP switching to RTP target address 192.168.6.102:8000 as source
-- <PJSIP/167-00000014> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:5] Dial("PJSIP/167-00000014", "PJSIP/168") in new stack
-- Called PJSIP/168
-- PJSIP/168-00000015 is ringing
> 0x7f740402a2e0 -- Strict RTP learning complete - Locking on source address 192.168.6.102:8000
== Everyone is busy/congested at this time (1:1/0/0)
-- Auto fallthrough, channel 'PJSIP/167-00000014' status is 'BUSY'
Step 10: Edit the extensions.conf file to use the GotoIf Application by using the below command
[root@linuxhelp asterisk]# vim extensions.conf
Add those following lines
[internal]
exten => _XXX,1,Set(repeat=5)
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 11: Login to the Asterisk CLI mode by using the below command
[root@linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvv
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 = 6348)
linuxhelp*CLI>
Step 12: Reload the dialplan by using the below 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.000007 sec
-- Time to delete the old dialplan: 0.000004 sec
-- Total time merge_contexts_delete: 0.000015 sec
-- pbx_config successfully loaded 1 contexts (enable debug for details).
linuxhelp*CLI>
Output:
- Executing [168@internal:1] Set("PJSIP/167-00000016", "repeat=5") in new stack
-- Executing [168@internal:2] Playback("PJSIP/167-00000016", "hello") in new stack
> 0x7f740402a2e0 -- Strict RTP learning after remote address set to: 192.168.6.102:8000
> 0x7f740402a2e0 -- Strict RTP switching to RTP target address 192.168.6.102:8000 as source
-- <PJSIP/167-00000016> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:3] Set("PJSIP/167-00000016", "repeat=4") in new stack
-- Executing [168@internal:4] GotoIf("PJSIP/167-00000016", "1?repeat:continue") in new stack
-- Goto (internal,168,2)
-- Executing [168@internal:2] Playback("PJSIP/167-00000016", "hello") in new stack
-- <PJSIP/167-00000016> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:3] Set("PJSIP/167-00000016", "repeat=3") in new stack
-- Executing [168@internal:4] GotoIf("PJSIP/167-00000016", "1?repeat:continue") in new stack
-- Goto (internal,168,2)
-- Executing [168@internal:2] Playback("PJSIP/167-00000016", "hello") in new stack
-- <PJSIP/167-00000016> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:3] Set("PJSIP/167-00000016", "repeat=2") in new stack
-- Executing [168@internal:4] GotoIf("PJSIP/167-00000016", "1?repeat:continue") in new stack
-- Goto (internal,168,2)
-- Executing [168@internal:2] Playback("PJSIP/167-00000016", "hello") in new stack
-- <PJSIP/167-00000016> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:3] Set("PJSIP/167-00000016", "repeat=1") in new stack
-- Executing [168@internal:4] GotoIf("PJSIP/167-00000016", "1?repeat:continue") in new stack
-- Goto (internal,168,2)
-- Executing [168@internal:2] Playback("PJSIP/167-00000016", "hello") in new stack
-- <PJSIP/167-00000016> Playing 'hello.ulaw' (language 'en')
-- Executing [168@internal:3] Set("PJSIP/167-00000016", "repeat=0") in new stack
-- Executing [168@internal:4] GotoIf("PJSIP/167-00000016", "0?repeat:continue") in new stack
-- Goto (internal,168,5)
-- Executing [168@internal:5] Dial("PJSIP/167-00000016", "PJSIP/168") in new stack
-- Called PJSIP/168
-- PJSIP/168-00000017 is ringing
> 0x7f740402a2e0 -- Strict RTP learning complete - Locking on source address 192.168.6.102:8000
== Everyone is busy/congested at this time (1:1/0/0)
-- Auto fallthrough, channel 'PJSIP/167-00000016' 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 GoTo and GotoIf Application on Asterisk on Oracle Linux 9.3. Your feedback is much welcome.
Comments ( 0 )
No comments available