TUTORIAL Gotcha-Free PBX: Scripts 101

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
15,136
Reaction score
2,627
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
15,136
Reaction score
2,627
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())
 

Members online

PIAF 5 - Powered by 3CX

Forum statistics

Threads
22,367
Messages
137,355
Members
14,575
Latest member
Issue