How to use GotoIfTime Application on Asterisk Dialplan context
To Use GotoIfTime Application On Asterisk Dialplan Context
GotoIfTime application is very identical to the GotoIf application, the difference is that allows you to jump to another extension, context, or priority if the current time matches the specified one.
Procedure
Step 1: Check the OS version by using the below command
root@linuxhelp1:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy
Step 2: Check the status of the Asterisk by using the below command
root@linuxhelp1:~# systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
Loaded: loaded (/etc/init.d/asterisk; generated)
Active: active (running) since Sun 2023-08-06 07:11:56 IST; 1h 9min ago
Docs: man:systemd-sysv-generator(8)
Process: 1418 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUCCESS)
Tasks: 71 (limit: 4537)
Memory: 131.2M
CPU: 1min 45.008s
CGroup: /system.slice/asterisk.service
└─1461 /usr/sbin/asterisk
Aug 06 07:11:56 linuxhelp1 systemd[1]: Starting LSB: Asterisk PBX...
Aug 06 07:11:56 linuxhelp1 asterisk[1418]: * Starting Asterisk PBX: asterisk
Aug 06 07:11:56 linuxhelp1 asterisk[1418]: ...done.
Aug 06 07:11:56 linuxhelp1 systemd[1]: Started LSB: Asterisk PBX.
Aug 06 07:12:03 linuxhelp1 asterisk[1461]: radcli: rc_read_config: rc_read_config: can't open /etc>
Aug 06 07:12:03 linuxhelp1 asterisk[1461]: radcli: rc_read_config: rc_read_config: can't open /etc>
Step 3: Move to the asterisk directory by using the below command
root@linuxhelp1:~# cd /etc/asterisk/
Step 4: Edit the extensions.conf file by using the below command
root@linuxhelp1:/etc/asterisk# vim extensions.conf
Add the following lines
[internal]
exten => _XXX,1,NoOp(How to use GotoIfTime Application)
exten => _XXX,2,GotoIFTime(08:00-08:30,mon-fri,1-31,jan-dec,Asia/Kolkata?open:close)
exten => _XXX,n(open),Playback(hello)
exten => _XXX,n(close),Hangup()
Step 5: Login to the Asterisk CLI mode by using the below command
root@linuxhelp1:/etc/asterisk# asterisk -rvvvvvvvvvvvvvvvvvvvvvvv
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 = 1461)
Step 6: Reload the dialplan by using the below command
linuxhelp1*CLI> dialplan reload
Dialplan reloaded.
-- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
-- Including switch 'Lua/' in context 'default'
-- Including switch 'Lua/' in context 'demo'
-- Including switch 'Lua/' in context 'public'
-- Including switch 'Lua/' in context 'local'
-- Time to scan old dialplan and merge leftovers back into the new: 0.000351 sec
-- Time to restore hints and swap in new dialplan: 0.000004 sec
-- Time to delete the old dialplan: 0.000103 sec
-- Total time merge_contexts_delete: 0.000458 sec
-- pbx_config successfully loaded 27 contexts (enable debug for details).
Output of the GotoIfTime Application if the condition is false
-- Executing [168@internal:1] NoOp("PJSIP/167-00000000", "How to use GotoIfTime Application") in new stack
-- Executing [168@internal:2] GotoIfTime("PJSIP/167-00000000", "08:00-08:30,mon-fri,1-31,jan-dec,Asia/Kolkata?open:close") in new stack
-- Goto (internal,168,4)
-- Executing [168@internal:4] Hangup("PJSIP/167-00000000", "") in new stack
== Spawn extension (internal, 168, 4) exited non-zero on 'PJSIP/167-00000000'
linuxhelp1*CLI>
Disconnected from Asterisk server
Asterisk cleanly ending (0).
Executing last minute clean-ups
Step 7: Edit the extensions.conf file for true condition by using the below command
root@linuxhelp1:/etc/asterisk# vim extensions.conf
Add the following lines
[internal]
exten => _XXX,1,NoOp(How to use GotoIfTime Application)
exten => _XXX,2,GotoIFTime(08:00-08:45,mon-fri,1-31,jan-dec,Asia/Kolkata?open:close)
exten => _XXX,n(open),Playback(hello)
exten => _XXX,n(close),Hangup()
Step 8: Again, login to the Asterisk CLI mode by using the below command
root@linuxhelp1:/etc/asterisk# asterisk -rvvvvvvvvvvvvvvvvvvvvvvv
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 = 1461)
Step 9: Reload the dialplan by using the below command
linuxhelp1*CLI> dialplan reload
Dialplan reloaded.
-- Including switch 'Lua/' in context 'local'
-- Including switch 'Lua/' in context 'public'
-- Including switch 'Lua/' in context 'demo'
-- Including switch 'Lua/' in context 'default'
-- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
-- Time to scan old dialplan and merge leftovers back into the new: 0.000240 sec
-- Time to restore hints and swap in new dialplan: 0.000005 sec
-- Time to delete the old dialplan: 0.000048 sec
-- Total time merge_contexts_delete: 0.000293 sec
-- pbx_config successfully loaded 27 contexts (enable debug for details).
Output of the GotoIfTime Application if the condition is true
-- Executing [168@internal:1] NoOp("PJSIP/167-00000004", "How to use GotoIfTime Application") in new stack
-- Executing [168@internal:2] GotoIfTime("PJSIP/167-00000004", "08:00-08:45,mon-fri,1-31,jan-dec,Asia/Kolkata?open:close") in new stack
-- Goto (internal,168,3)
-- Executing [168@internal:3] Playback("PJSIP/167-00000004", "hello") in new stack
> 0x7fd4c4013960 -- Strict RTP learning after remote address set to: 192.168.6.101:4006
-- <PJSIP/167-00000004> Playing 'hello.ulaw' (language 'en')
> 0x7fd4c4013960 -- Strict RTP switching to RTP target address 192.168.6.101:4006 as source
-- Executing [168@internal:4] Hangup("PJSIP/167-00000004", "") in new stack
== Spawn extension (internal, 168, 4) exited non-zero on 'PJSIP/167-00000004'
Conclusion:
By this How to use GotoIfTime Application on Asterisk Dialplan context has come to an end.
Comments ( 0 )
No comments available