How to use Asterisk GotoIfTime Condition on Debian 12
To Use Asterisk GOTOIFTIME Application On Debian 12
Introduction:
This application will set the context, extension, and priority in the channel structure based on the evaluation of 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 as 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
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 the below command.
root@linuxhelp:~# asterisk -V
Asterisk 20.4.0
Step 3: Go to the following location by using the below command.
root@linuxhelp:~# cd /etc/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:/etc/asterisk# vim extensions.conf
[internal]
exten => 110,1,NoOp(Extension 110)
same=>n,Answer()
same=>n,NoOP()
same=>n,GotoIfTime(01:25-01:35,*,*,*?time:111,after")
same=>n,Playback(welcome)
same=>n(time),Dial(PJSIP/110, 10)
same=>n,Playback(hangup)
same=>n,Hangup()
exten =>111,1,NoOp(Extension 111)
same=>n,Answer()
same=>n(after),Playback(welcome)
same=>n,Dial(PJSIP/111, 10)
same=>n,Playback(hangup)
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 5: Login to the Asterisk Console by using the below command.
root@linuxhelp:~# asterisk -rvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
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)
Step 6: Reload the dialplan in the Asterisk Console by using the below command.
linuxhelp*CLI> dialplan reload
Dialplan reloaded.
-- Time to scan old dialplan and merge leftovers back into the new: 0.000006 sec
-- Time to restore hints and swap in new dialplan: 0.000006 sec
-- Time to delete the old dialplan: 0.000012 sec
-- Total time merge_contexts_delete: 0.000024 sec
-- pbx_config successfully loaded 1 contexts (enable debug for details).
Step 7: Make the call to check the time condition if true by using MicroSIP application as shown in below image.
-- Executing [110@internal:1] NoOp("PJSIP/112-0000000e", "Extension 110") in new stack
-- Executing [110@internal:2] Answer("PJSIP/112-0000000e", "") in new stack
> 0x7fbf7c017200 -- Strict RTP learning after remote address set to: 192.168.6.107:4028
-- Executing [110@internal:3] GotoIfTime("PJSIP/112-0000000e", "01:25-01:35,*,*,*?time:111,after") in new stack
-- Goto (internal,110,4)
-- Executing [110@internal:4] Playback("PJSIP/112-0000000e", "welcome") in new stack
-- <PJSIP/112-0000000e> Playing 'welcome.ulaw' (language 'en')
> 0x7fbf7c017200 -- Strict RTP switching to RTP target address 192.168.6.107:4028 as source
-- Executing [110@internal:5] Dial("PJSIP/112-0000000e", "PJSIP/110, 10") in new stack
-- Called PJSIP/110
-- PJSIP/110-0000000f is ringing
> 0x7fbf7c017200 -- Strict RTP learning complete - Locking on source address 192.168.6.107:4028
== Everyone is busy/congested at this time (1:1/0/0)
-- Executing [110@internal:6] Playback("PJSIP/112-0000000e", "hangup") in new stack
[Jan 23 01:29:12] WARNING[8320][C-0000000e]: file.c:824 ast_openstream_full: File hangup does not exist in any format
[Jan 23 01:29:12] WARNING[8320][C-0000000e]: file.c:1303 ast_streamfile: Unable to open hangup (format (ulaw)): No such file or directory
[Jan 23 01:29:12] WARNING[8320][C-0000000e]: app_playback.c:512 playback_exec: Playback failed on PJSIP/112-0000000e for hangup
-- Executing [110@internal:7] Hangup("PJSIP/112-0000000e", "") in new stack
== Spawn extension (internal, 110, 7) exited non-zero on 'PJSIP/112-0000000e'
Step 8: Edit the extensions.conf file and change the time in dialplan configuration by using the below command.
root@linuxhelp:/etc/asterisk# vim extensions.conf
[internal]
exten => 110,1,NoOp(Extension 110)
same=>n,Answer()
same=>n,NoOP()
same=>n,GotoIfTime(12:00-01:00,*,*,*?time:111,after")
same=>n,Playback(welcome)
same=>n(time),Dial(PJSIP/110, 10)
same=>n,Playback(hangup)
same=>n,Hangup()
exten =>111,1,NoOp(Extension 111)
same=>n,Answer()
same=>n(after),Playback(welcome)
same=>n,Dial(PJSIP/111, 10)
same=>n,Playback(hangup)
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 9: Reload the dialplan in the Asterisk Console by using the below command.
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.000014 sec
-- Time to delete the old dialplan: 0.000003 sec
-- Total time merge_contexts_delete: 0.000020 sec
-- pbx_config successfully loaded 1 contexts (enable debug for details).
Step 10: Make the call to check time condion if false by using MicroSIP Software as shown in below image.
-- Executing [110@internal:1] NoOp("PJSIP/112-00000012", "Extension 110") in new stack
-- Executing [110@internal:2] Answer("PJSIP/112-00000012", "") in new stack
> 0x7fbf7c03f1b0 -- Strict RTP learning after remote address set to: 192.168.6.107:4032
-- Executing [110@internal:3] GotoIfTime("PJSIP/112-00000012", "12:00-01:00,*,*,*?time:111,after") in new stack
-- Goto (internal,111,3)
-- Executing [111@internal:3] Playback("PJSIP/112-00000012", "welcome") in new stack
-- <PJSIP/112-00000012> Playing 'welcome.ulaw' (language 'en')
> 0x7fbf7c03f1b0 -- Strict RTP switching to RTP target address 192.168.6.107:4032 as source
-- Executing [111@internal:4] Dial("PJSIP/112-00000012", "PJSIP/111, 10") in new stack
-- Called PJSIP/111
-- PJSIP/111-00000013 is ringing
> 0x7fbf7c03f1b0 -- Strict RTP learning complete - Locking on source address 192.168.6.107:4032
== Everyone is busy/congested at this time (1:1/0/0)
-- Executing [111@internal:5] Playback("PJSIP/112-00000012", "hangup") in new stack
[Jan 23 01:34:03] WARNING[8559][C-00000010]: file.c:824 ast_openstream_full: File hangup does not exist in any format
[Jan 23 01:34:03] WARNING[8559][C-00000010]: file.c:1303 ast_streamfile: Unable to open hangup (format (ulaw)): No such file or directory
[Jan 23 01:34:03] WARNING[8559][C-00000010]: app_playback.c:512 playback_exec: Playback failed on PJSIP/112-00000012 for hangup
-- Executing [111@internal:6] Hangup("PJSIP/112-00000012", "") in new stack
== Spawn extension (internal, 111, 6) exited non-zero on 'PJSIP/112-00000012'
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to use Asterisk GOTOIFTIME Application on Debian 12. Your feedback is much welcome.
Use core show date to confirm the current date and time.
Enable verbose logging (core set debug 9) to see detailed execution of the GotoIfTime statement.
Check for typos or syntax errors in your time/date expression.
Use the asterisk community forum or mailing list for further assistance.
Directing calls to voicemail or a specific queue during holidays or closed periods.
Offering discounted rates or promotions during certain times of the day.
Implementing seasonal routing based on the current month or time of year.
time/date expression: This specifies the condition to be evaluated. It can be a simple time range (e.g., "08:00-17:00"), a day of the week (e.g., "mon-fri"), a combination of both, or even complex expressions using operators like "!", "?," and "|".
label: This is the destination label to jump to if the expression evaluates to true. It can be an extension number, another context, or a priority within the current context.
options (optional): These provide additional control over the behavior. Some common options include:
n: Jump to the next priority in the current context if the expression is false.
?:: Use silent matching, meaning the GotoIfTime statement doesn't appear in call logs.
GotoIfTime Example: https://www.voip-info.org/asterisk-cmd-gotoif/
Asterisk Community Forum: https://community.asterisk.org/