How to use Asterisk Dialplan Functions on Debian 12
To Use Functions On Asterisk Dialplan Context
Introduction:
Asterisk functions are very similar to functions in many programming languages. Functions are: Sophisticated subroutines that help you manipulate data in a variety of ways. Callable from within Dialplan and Asterisk's various interfaces.
Procedure:
Step 1: Check the OS version by using following command.
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
Step 2: Goto the following location by using following command.
root@linuxhelp:~# cd /etc/asterisk/
Step 3: Edit the extensions.conf file for use dialplan functions by using following command.
root@linuxhelp:/etc/asterisk# vim extensions.conf
[internal]
exten => 110,1,NoOp(Result for my function: ${CALLERID(all)})
same => n,Dial(PJSIP/110, 20)
same => n,Playback(sorry_didnt_get)
same => n,Hangup()
exten => 111,1,NoOp(Print the context)
same => n,Dial(PJSIP/111, 20)
same => n,Playback(sorry_didnt_get)
same => n,Hangup()
exten => 112,1,NoOp()
same => n,Dial(PJSIP/112, 20)
same => n,Playback(sorry_didnt_get)
same => n,Hangup()
Step 4: Login to the asterisk console by using following command.
root@linuxhelp:/etc/asterisk# sudo asterisk -rvvvvvvvvvvvvvvv
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 = 953)
linuxhelp*CLI>
Step 5: Reload the dialplan by using following 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.000006 sec
-- Total time merge_contexts_delete: 0.000018 sec
-- pbx_config successfully loaded 1 contexts (enable debug for details).
Step 6: Make a Call to Check Dialplan Functions by using Softphone Softwares.
linuxhelp*CLI>
-- Executing [110@internal:1] NoOp("PJSIP/112-00000010", "Result for my function: "linuxhelp3" <112>") in new stack
-- Executing [110@internal:2] Dial("PJSIP/112-00000010", "PJSIP/110, 20") in new stack
-- Called PJSIP/110
-- PJSIP/110-00000011 is ringing
-- Nobody picked up in 20000 ms
-- Executing [110@internal:3] Playback("PJSIP/112-00000010", "sorry_didnt_get") in new stack
> 0x7f5708012710 -- Strict RTP learning after remote address set to: 192.168.6.102:8000
> 0x7f5708012710 -- Strict RTP switching to RTP target address 192.168.6.102:8000 as source
-- <PJSIP/112-00000010> Playing 'sorry_didnt_get.ulaw' (language 'en')
-- Executing [110@internal:4] Hangup("PJSIP/112-00000010", "") in new stack
== Spawn extension (internal, 110, 4) exited non-zero on 'PJSIP/112-00000010'
Step 7: Check all the functions of asterisk by using following command.
linuxhelp*CLI> core show functions
Installed Custom Functions:
--------------------------------------------------------------------------------
AMI_CLIENT AMI_CLIENT(loginname,field) Checks attributes of manager accounts
ARRAY ARRAY(var1[,var2[,...][,varN]]) Allows setting multiple variables at once.
AST_SORCERY AST_SORCERY(module_name,object_type Get a field from a sorcery object
CALLERID CALLERID(datatype[,CID]) Gets or sets Caller*ID data on the channel.
CDR CDR(name[,options]) Gets or sets a CDR variable.
CDR_PROP CDR_PROP(name) Set a property on a channel's CDR.
CONFBRIDGE CONFBRIDGE(type,option) Set a custom dynamic bridge, user, or menu profile on a channel for the ConfBridge application using the same options available in confbridge.conf.
CONFBRIDGE_CHANNELS CONFBRIDGE_CHANNELS(type,conf) Get a list of channels in a ConfBridge conference.
CONFBRIDGE_INFO CONFBRIDGE_INFO(type,conf) Get information about a ConfBridge conference.
CONNECTEDLINE CONNECTEDLINE(datatype[,i]) Gets or sets Connected Line data on the channel.
CSV_QUOTE CSV_QUOTE(string) Quotes a given string for use in a CSV file, escaping embedded quotes as necessary
DEVICE_STATE DEVICE_STATE(device) Get or Set a device state.
EVAL EVAL(variable) Evaluate stored variables
EXCEPTION EXCEPTION(field) Retrieve the details of the current dialplan exception.
FEATURE FEATURE(option_name) Get or set a feature option on a channel.
FEATUREMAP FEATUREMAP(feature_name) Get or set a feature map to a given value on a specific channel.
FIELDNUM FIELDNUM(varname,delim,value) Return the 1-based offset of a field in a list
FIELDQTY FIELDQTY(varname,delim) Count the fields with an arbitrary delimiter
FILTER FILTER(allowed-chars,string) Filter the string to include only the allowed characters
HASH HASH(hashname[,hashkey]) Implementation of a dialplan associative array
HASHKEYS HASHKEYS(hashname) Retrieve the keys of the HASH() function.
HINT HINT(extension[@context][,options]) Get the devices set for a dialplan hint.
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to use Asterisk Dialplan Functions on Debian 12. Your feedback is much welcome.