How to create an Asterisk Dialplan Context on Rocky Linux 9.4
To Create An Asterisk Dialplan Context On Rocky Linux 9.4
Introduction:
The Asterisk Dialplans play a crucial role in call routing, often referred to as the central component of the system. These Dialplans are scripted in a powerful language, enabling extensive functionality. Asterisk functions beyond a basic phone system, facilitating call reception and connection services.
Procedure:
Step 1: Check the System OS version by using the below command
[root@Linuxhelp ~]# cat /etc/os-release
NAME="Rocky Linux"
VERSION="9.4 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.4"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.4 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.4"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.4"
Step 2 : Verify the status of the Asterisk service by using the below command
[root@Linuxhelp ~]# systemctl status asterisk
● asterisk.service - LSB: Asterisk PBX
Loaded: loaded (/etc/rc.d/init.d/asterisk; generated)
Active: active (running) since Sun 2024-06-23 23:24:59 IST; 1 day 1h ago
Docs: man:systemd-sysv-generator(8)
Main PID: 1224
Tasks: 39 (limit: 48597)
Memory: 69.7M
CPU: 21.576s
CGroup: /system.slice/asterisk.service
├─1221 /bin/sh /usr/sbin/safe_asterisk
└─5288 /usr/sbin/asterisk -f -vvvg -c
Jun 23 23:24:59 Linuxhelp systemd[1]: Starting LSB: Asterisk PBX...
Jun 23 23:24:59 Linuxhelp asterisk[1140]: Starting asterisk:
Jun 23 23:24:59 Linuxhelp systemd[1]: asterisk.service: Can't open PID file /run/asterisk/asterisk.pid (yet?) after s>
Jun 23 23:24:59 Linuxhelp systemd[1]: asterisk.service: Supervising process 1224 which is not our child. We'll most l>
Jun 23 23:24:59 Linuxhelp systemd[1]: Started LSB: Asterisk PBX.
Jun 23 23:25:54 Linuxhelp systemd[1]: /run/systemd/generator.late/asterisk.service:30: PIDFile= references a path bel>
Jun 23 23:26:17 Linuxhelp systemd[1]: /run/systemd/generator.late/asterisk.service:30: PIDFile= references a path bel>
Step 3 : Enter into the Asterisk CLI console by using the below command
[root@Linuxhelp ~]# asterisk -rvvvvvvvvvvvv
Asterisk 20.8.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.8.1 currently running on Linuxhelp (pid = 5288)
Step 4 : View the endpoints by using the below command
Linuxhelp*CLI> pjsip show endpoints
Endpoint: <Endpoint/CID.....................................> <State.....> <Channels.>
I/OAuth: <AuthId/UserName...........................................................>
Aor: <Aor............................................> <MaxContact>
Contact: <Aor/ContactUri..........................> <Hash....> <Status> <RTT(ms)..>
Transport: <TransportId........> <Type> <cos> <tos> <BindAddress..................>
Identify: <Identify/Endpoint.........................................................>
Match: <criteria.........................>
Channel: <ChannelId......................................> <State.....> <Time.....>
Exten: <DialedExten...........> CLCID: <ConnectedLineCID.......>
==========================================================================================
Endpoint: 167/167 Not in use 0 of inf
InAuth: 167/167
Aor: 167 1
Contact: 167/sip:167@192.168.6.102:51533;transport= 8304757b99 Avail 2.588
Endpoint: 168/168 Not in use 0 of inf
InAuth: 168/168
Aor: 168 1
Contact: 168/sip:168@192.168.6.102:53569;ob 4a0826fe04 Avail 0.992
Objects found: 2
Step 5 : Exit from the Asterisk CLI console by using the below command
Linuxhelp*CLI> exit
Asterisk cleanly ending (0).
Executing last minute cleanups
Step 6: Edit the extensions.conf file to modify the dialplan by using the vim text editor
[root@Linuxhelp ~]# vim /etc/asterisk/extensions.conf
[internal]
exten => 167,1,NoOp(Call started for ${EXTEN})
exten => 167,2,Dial(PJSIP/167,10)
exten => 167,3,Playback()
exten => 167,4,Hangup()
exten => 168,2,Dial(PJSIP/167)
Step 7: Enter into the Asterisk CLI Console and reload the dialplan by using the below command
[root@Linuxhelp ~]# asterisk -rvvvvvvvvvvvvvvv
Asterisk 20.8.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.8.1 currently running on Linuxhelp (pid = 5288)
Linuxhelp*CLI> dialplan reload
Dialplan reloaded.
> Time to scan old dialplan and merge leftovers back into the new: 0.000005 sec
> Time to restore hints and swap in new dialplan: 0.000041 sec
> Time to delete the old dialplan: 0.000003 sec
> Total time merge_contexts_delete: 0.000049 sec
> pbx_config successfully loaded 1 contexts (enable debug for details).
Output:-
-- Executing [167@internal:1] NoOp("PJSIP/168-0000001c", "call started from 167") in new stack
-- Executing [167@internal:2] Dial("PJSIP/168-0000001c", "PJSIP/167,10") in new stack
-- Called PJSIP/167
-- PJSIP/167-0000001d is ringing
-- Nobody picked up in 10000 ms
-- Executing [167@internal:3] Playback("PJSIP/168-0000001c", "") in new stack
[Jun 25 00:48:40] WARNING[7243][C-0000000f]: app_playback.c:471 playback_exec: Playback requires an argument (filename)
== Spawn extension (internal, 167, 3) exited non-zero on 'PJSIP/168-0000001c'
Step 8: Exit from the Asterisk CLI console
Linuxhelp*CLI> exit
Asterisk cleanly ending (0).
Executing last minute cleanups
Step 9: To overcome the above “Playback requires an argument (filename)” Error. Move to the Asterisk default sound directory by using the below command
[root@Linuxhelp ~]# cd /var/lib/asterisk/sounds/en
Step 10: Long List the files and copy any of the sound file name without the extensions by using the below coomand
[root@Linuxhelp en]# ls
1-for-am-2-for-pm.alaw north.siren14
1-for-am-2-for-pm.g722 north.siren7
1-for-am-2-for-pm.g729 north.sln16
1-for-am-2-for-pm.gsm north.ulaw
1-for-am-2-for-pm.siren14 north.wav
nobody-but-chickens.siren14 your-account.alaw
nobody-but-chickens.siren7 your-account.g722
nobody-but-chickens.sln16 your-account.g729
nobody-but-chickens.ulaw your-account.gsm
nobody-but-chickens.wav your-account.siren14
node.alaw your-account.siren7
node.g722 your-account.sln16
node.g729 your-account.ulaw
node.gsm your-account.wav
node.siren14 your.alaw
node.siren7 yourcallisimportant.alaw
node.sln16 yourcallisimportant.g722
node.ulaw yourcallisimportant.g729
node.wav yourcallisimportant.gsm
no-empty-conferences.alaw yourcallisimportant.siren14
no-empty-conferences.g722 yourcallisimportant.siren7
no-empty-conferences.g729 yourcallisimportant.sln16
no-empty-conferences.gsm yourcallisimportant.ulaw
no-empty-conferences.siren14 yourcallisimportant.wav
no-empty-conferences.siren7 yourcallisimpotent.alaw
no-empty-conferences.sln16 yourcallisimpotent.g722
no-empty-conferences.ulaw yourcallisimpotent.g729
no-empty-conferences.wav yourcallisimpotent.gsm
no-info-about-number.alaw yourcallisimpotent.siren14
no-info-about-number.g722 yourcallisimpotent.siren7
no-info-about-number.g729 yourcallisimpotent.sln16
no-info-about-number.gsm yourcallisimpotent.ulaw
no-info-about-number.siren14 yourcallisimpotent.wav
no-info-about-number.siren7 your.g722
no-info-about-number.sln16 your.g729
north.alaw you-sound-cute.siren7
north-carolina.alaw you-sound-cute.sln16
north-carolina.g722 you-sound-cute.ulaw
north-carolina.g729 you-sound-cute.wav
north-carolina.gsm you-wish-to-join.alaw
north-carolina.siren14 you-wish-to-join.g722
north-carolina.siren7 you-wish-to-join.g729
north-carolina.sln16 you-wish-to-join.gsm
north-carolina.ulaw you-wish-to-join.siren14
north-carolina.wav you-wish-to-join.siren7
north-dakota.alaw you-wish-to-join.sln16
north-dakota.g722 you-wish-to-join.ulaw
north-dakota.g729 you-wish-to-join.wav
north-dakota.gsm zip-code.alaw
north-dakota.siren14 zip-code.g722
north-dakota.siren7 zip-code.g729
north-dakota.sln16 zip-code.gsm
north-dakota.ulaw zip-code.siren14
north-dakota.wav zip-code.siren7
northerly.alaw zip-code.sln16
northerly.g722 zip-code.ulaw
northerly.g729 zip-code.wav
northerly.gsm zombies.alaw
northerly.siren14 zombies.g722
northerly.siren7 zombies.g729
northerly.sln16 zombies.gsm
northerly.ulaw zombies.siren14
northerly.wav zombies.siren7
north.g722 zombies.sln16
north.g729 zombies.ulaw
north.gsm zombies.wav
Step 11: After copied the sound file name then paste in the Playback location from the below file
[root@Linuxhelp en]# vim /etc/asterisk/extensions.conf
[internal]
exten => 167,1,NoOp(call started from ${EXTEN})
exten => 167,2,Dial(PJSIP/167,10)
exten => 167,3,Playback(yourcallisimportant)
exten => 167,4,Hangup()
exten => 168,1,Dial(PJSIP/168)
Step 12 : Now Enter into the Asterisk CLI console and reload the Dialplan
[root@Linuxhelp en]# asterisk -rvvvvvvvvvvvvvvv
Asterisk 20.8.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.8.1 currently running on Linuxhelp (pid = 5288)
Linuxhelp*CLI> dialplan reload
Dialplan reloaded.
> Time to scan old dialplan and merge leftovers back into the new: 0.000002 sec
> Time to restore hints and swap in new dialplan: 0.000003 sec
> Time to delete the old dialplan: 0.000003 sec
> Total time merge_contexts_delete: 0.000008 sec
> pbx_config successfully loaded 1 contexts (enable debug for details).
Output:-
-- Executing [167@internal:1] NoOp("PJSIP/168-0000001e", "call started from 167") in new stack
-- Executing [167@internal:2] Dial("PJSIP/168-0000001e", "PJSIP/167,10") in new stack
-- Called PJSIP/167
-- PJSIP/167-0000001f is ringing
-- Nobody picked up in 10000 ms
-- Executing [167@internal:3] Playback("PJSIP/168-0000001e", "yourcallisimportant") in new stack
> 0x7fdd7801df40 -- Strict RTP learning after remote address set to: 192.168.6.102:4030
-- <PJSIP/168-0000001e> Playing 'yourcallisimportant.ulaw' (language 'en')
> 0x7fdd7801df40 -- Strict RTP learning after remote address set to: 192.168.6.102:4030
> 0x7fdd7801df40 -- Strict RTP switching to RTP target address 192.168.6.102:4030 as source
> 0x7fdd7801df40 -- Strict RTP learning complete - Locking on source address 192.168.6.102:4030
-- Executing [167@internal:4] Hangup("PJSIP/168-0000001e", "") in new stack
== Spawn extension (internal, 167, 4) exited non-zero on 'PJSIP/168-0000001e'
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to create Asterisk Dialplan context on Rocky Linux 9.4. Your feedback is much welcome.
sudo asterisk -r
dialplan reload
exten => 300,1,Answer()
exten => 300,2,Playback(demo-congrats)
exten => 300,3,Hangup()