TUTORIAL Gotcha-Free PBX: Scripts 101

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,170
Reaction score
5,199
Incredible PBX for Asterisk-GUI was designed in a modular way to make it easy to add your own Custom Scripts and those of others as we move forward. The scripts can be activated for all-trunks for incoming and/or outgoing calls. Or scripts can be activated for an individual trunk for incoming and/or outgoing calls. Moving forward, we will provide a number of custom scripts that are developed by us and by others. There's no practical limit to the number of custom scripts you can include in your dialplan.

NOTE: These scripts are subroutines designed to return control to the existing dialplan. Do NOT use them to branch to a destination! We'll cover that separately.

In its most basic form, a Custom Script looks like this and is added at the end of extensions_custom.conf:
Code:
;# // BEGIN demo-script
[demo-script]
exten => s,1,Noop("here is a demo script")
exten => s,n,Return()
;# // END demo-script

The BEGIN and END markers are important. They make it easy to remove and replace a script with just two lines of code:
Code:
sed -i '\:// BEGIN demo-script:,\:// END demo-script:d' /etc/asterisk/extensions_custom.conf
cat demo-script.pbx >> /etc/asterisk/extensions_custom.conf

To activate a Custom Script for ALL Incoming Calls:

Insert a Gosub line in [incoming-sub] in extensions_custom.conf before the Return() command:
Code:
exten => incoming-sub_1,n,Gosub(demo-script,s,1())
exten => incoming-sub_1,n,Return()

To activate a Custom Script for ALL Outgoing Calls:

Insert a Gosub line in [outgoing-sub] in extensions_custom.conf before the Return() command:
Code:
exten => outgoing-sub_1,n,Gosub(demo-script,s,1())
exten => outgoing-sub_1,n,Return()

To activate a Custom Script for Incoming Calls on an Individual Trunk:

Insert a Gosub line in DID_sometrunk_default in extensions.conf just before the Goto command that sends a call off to its final destination:
Code:
exten = _.,n,Gosub(demo-script,s,1())
exten = _.,n,Goto(voicemenu-custom-1,s,1) ; routes incoming call to Stealth AutoAttendant

To activate a Custom Script for Outgoing Calls on an Individual Trunk:

Insert a Gosub line in CallingRule_sometrunk in extensions.conf just before the Goto(outbound-allroutes) command (NOTE: there may be more than one entry and be careful to always match the XXX dial string of the trunk):
Code:
exten = _NXXNXXXXXX,n,Gosub(demo-script,s,1())
exten = _NXXNXXXXXX,n,Goto(outbound-allroutes,${EXTEN},1)

Whenever you add scripts or make changes in your dialplan: asterisk-reload

See also:
 

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,170
Reaction score
5,199
To Filter Calls within a Custom Script:

There are times when only calls from a certain CallerID or from one of several Channels used by a trunk or some other condition need to be processed separately by a Custom Script. The easiest way to do this is to add GotoIf logic within the script. To review the variables that Asterisk sets for calls, add the following line of code to your Custom Script and use the variables you need from there:
Code:
exten => s,n,Gosub(macro-dumpvars,s,1())

B9uJExyIcAAhBX3.jpg:large
 

Members online

Forum statistics

Threads
25,782
Messages
167,512
Members
19,203
Latest member
frapu
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top