How to use GotoIfTime application on Asterisk Dialplan Context On Oracle Linux 9.3

To Use The GotoIfTime Application On Asterisk Dialplan Context On Oracle Linux 9.3

Inroduction:

This application will set the context, extension, and priority in the channel structure based on evaluating the given time specification. After this application completes, the PBX engine will continue dialplan execution at the specified location in the dialplan. If the current time is within the given time specification, the channel will continue at labeliftrue. Otherwise, the channel will continue at labeliffalse. If the label chosen by the condition is omitted, no jump is performed, and execution passes to the next instruction. If the target jump location is bogus, the same actions would be taken for 'Goto'. Further information on the time specification can be found in examples illustrating how to do time-based context included in the dialplan.

Procedure Steps:

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: Next check the status of Asterisk service by using the Following Commands

[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-03-29 18:37:00 IST; 2h 2min ago
       Docs: man:systemd-sysv-generator(8)
    Process: 7420 ExecStart=/etc/rc.d/init.d/asterisk start (code=exited, status=0/SUCCESS)
   Main PID: 7449 (asterisk)
      Tasks: 41 (limit: 21739)
     Memory: 49.7M
        CPU: 52.652s
     CGroup: /system.slice/asterisk.service
             ├─7447 /bin/sh /usr/sbin/safe_asterisk
             └─7449 /usr/sbin/asterisk -f -vvvg -c

Mar 29 18:37:00 linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
Mar 29 18:37:00 linuxhelp asterisk[7420]: Starting asterisk:
Mar 29 18:37:00 linuxhelp systemd[1]: asterisk.service: Can't open PID file /run/asterisk/asterisk.pid (yet?) after start: Operation not permitted
Mar 29 18:37:00 linuxhelp systemd[1]: asterisk.service: Supervising process 7449 which is not our child. We'll most likely not notice when it exits.
Mar 29 18:37:00 linuxhelp systemd[1]: Started LSB: Asterisk PBX.

Step 3: Go to the following location by using the below command.

[root@linuxhelp ~]# cd /etc	/asterisk
[root@linuxhelp asterisk]#

Step 4: Edit the extensions.conf file and make dialplan configuration with gotoiftime application for time condition by using the below command.

[root@linuxhelp asterisk]# vim extensions.conf

Add the following lines
[internal]
exten => 167,1,Goto(s,1)
exten => s,1,GotoIfTime(17:00-18:00|*|*|*?s,2)
;exten => s,2,Monitor(wav,test,m)
exten => s,2,BackGround(tt-monkeys)
exten => s,3,StopMonitor()
;exten => 1,1,StopMonitor()

exten => 168,1,Answer()
exten => n,Dial(PJSIP/168,10)

Step 5: Now Login to the asterisk CLI Mode by using the following command

[root@linuxhelp asterisk]# asterisk -rvvvvvvvvvvvvvvvvvvvvvvvvv
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 = 7449)
linuxhelp*CLI>

Step 6: After login the asterisk CLI mode, Once reload the dialplan by using the following commands

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

Step 7: Now make a call from 167 extensions to 168 extensions.

Output:
   -- Executing [168@internal:1] Answer("PJSIP/167-00000061", "") in new stack
       > 0x7f121400f1b0 -- Strict RTP learning after remote address set to: 192.168.6.102:8000
       > 0x7f121400f1b0 -- Strict RTP switching to RTP target address 192.168.6.102:8000 as source
    -- Executing [168@internal:2] Goto("PJSIP/167-00000061", "s,1") in new stack
    -- Goto (internal,s,1)
    -- Executing [s@internal:1] GotoIfTime("PJSIP/167-00000061", "20:00-21:00|fri|*|*?s,2:3") in new stack
    -- Goto (internal,s,2)
    -- Executing [s@internal:2] BackGround("PJSIP/167-00000061", "tt-monkeys") in new stack
    -- <PJSIP/167-00000061> Playing 'tt-monkeys.ulaw' (language 'en')
       > 0x7f121400f1b0 -- Strict RTP learning complete - Locking on source address 192.168.6.102:8000
[Mar 29 20:50:09] WARNING[10020][C-00000058]: pbx.c:2928 pbx_extension_helper: No application 'StopMonitor' for extension (internal, s, 3)
  == Spawn extension (internal, s, 3) exited non-zero on 'PJSIP/167-00000061'

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to use GotoIfTime application on Asterisk Dialplan Context on Oracle Linux 9.3. Your feedback is much welcome.

FAQ
Q
How do you view the SIP extensions?
A
By using the following command on the asterisk CLI pjsip show endpoints
Q
Which file contains the dialplan context?
A
/etc/asterisk/extension.conf
Q
How to reload the Dialplan?
A
By using the following command on the asterisk CLI Dialplan reload
Q
How to use the GotoIfTime application?
A
Syntax : GotoIfTime(times,weekdays,mdays,months,[timezone]?truelabel:falselabel)
Q
What is the function of the GotoIfTime application?
A
Conditional Goto based on the current time.