How to use priority label on Asterisk dialplan context

To Use Priority Labels On Asterisk Dialplan Context

Introduction

Priority Labels are used to assign a label to a particular priority number by placing the label in parentheses directly after the priority number. Labels make it easier to jump back to a particular location within the extension at a later time.

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: Already I installed Asterisk so, I am going to 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 Fri 2023-07-28 07:47:59 IST; 19min ago
       Docs: man:systemd-sysv-generator(8)
    Process: 1413 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUCCESS)
      Tasks: 71 (limit: 4537)
     Memory: 131.5M
        CPU: 16.608s
     CGroup: /system.slice/asterisk.service
             └─1434 /usr/sbin/asterisk

Jul 28 07:47:58 linuxhelp1 systemd[1]: Starting LSB: Asterisk PBX...
Jul 28 07:47:59 linuxhelp1 asterisk[1413]:  * Starting Asterisk PBX: asterisk
Jul 28 07:47:59 linuxhelp1 asterisk[1413]:    ...done.
Jul 28 07:47:59 linuxhelp1 systemd[1]: Started LSB: Asterisk PBX.
Jul 28 07:48:06 linuxhelp1 asterisk[1434]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng>
Jul 28 07:48:06 linuxhelp1 asterisk[1434]: radcli: rc_read_config: rc_read_config: can't open /etc/radiusclient-ng>

Step 3: Move to the Asterisk directory by using the below command

root@linuxhelp1:~# cd /etc/asterisk/

Step 4: Edit the extensions.conf file to use priority label by using the below command

root@linuxhelp1:/etc/asterisk# vim extensions.conf
Add the following lines
[internal]
exten => _XXX,1,NoOp(Call started for ${EXTEN})
exten => _XXX,n,Goto(skip)
exten => _XXX,n,Playback(hello)
exten => _XXX,n(skip),Dial(PJSIP/${EXTEN})

Step 5: Login to the Asterisk CLI mode by using the below command

root@linuxhelp1:/etc/asterisk# asterisk -rvvvvvvvvvvvvvvvvvvvvvvvvvvv
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 = 1434)

Step 6: Reload the dialplan by using the below command

linuxhelp1*CLI> dialplan reload
Dialplan reloaded.
    -- Including switch 'Lua/' in context 'default'
    -- Including switch 'Lua/' in context 'local'
    -- Including switch 'Lua/' in context 'demo'
    -- Including switch 'Lua/' in context 'public'
    -- Including switch 'DUNDi/e164' in context 'ael-dundi-e164-switch'
    -- Time to scan old dialplan and merge leftovers back into the new: 0.000741 sec
    -- Time to restore hints and swap in new dialplan: 0.000007 sec
    -- Time to delete the old dialplan: 0.000131 sec
    -- Total time merge_contexts_delete: 0.000879 sec
    -- pbx_config successfully loaded 27 contexts (enable debug for details).

Output of the priority label while calling between extensions
    -- Added contact 'sip:167@192.168.6.101:56618;transport=TCP;ob' to AOR '167' with expiration of 300 seconds
  == Endpoint 167 is now Reachable
    -- Contact 167/sip:167@192.168.6.101:56618;transport=TCP;ob is now Reachable.  RTT: 4.113 msec
    -- Added contact 'sip:169@192.168.6.101:56622;transport=TCP;ob' to AOR '169' with expiration of 300 seconds
  == Endpoint 169 is now Reachable
    -- Contact 169/sip:169@192.168.6.101:56622;transport=TCP;ob is now Reachable.  RTT: 12.199 msec
    -- Executing [169@internal:1] NoOp("PJSIP/167-00000000", "Call started for 169") in new stack
    -- Executing [169@internal:2] Goto("PJSIP/167-00000000", "skip") in new stack
    -- Goto (internal,169,4)
    -- Executing [169@internal:4] Dial("PJSIP/167-00000000", "PJSIP/169") in new stack
    -- Called PJSIP/169
    -- PJSIP/169-00000001 is ringing
  == Spawn extension (internal, 169, 4) exited non-zero on 'PJSIP/167-00000000'

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required how to use priority label on Asterisk dialplan context. Your feedback is much welcome.

FAQ
Q
Where is the dialplan location on the Asterisk?
A
/etc/asterisk/extensions.conf
Q
How to reload the dialplan context?
A
Login to the asterisk CLI mode and run the dialplan reload command to reload.
Q
Where we will use the priority label?
A
We are using the priority labels on the dialplan context
Q
How to use priority labels?
A
exten => extension,priority(label),Application)
Q
What is the use of the priority labels?
A
Labels make it easier to jump back to a particular location within the extension at a later time.