Extensions Class (Manipulating Dialplan)
- 1 Introduction
- 2 Core Methods
- 2.1 add
- 2.1.1 Example
- 2.2 splice
- 2.2.1 Example
- 2.3 replace
- 2.4 remove
- 2.5 addSectionComment
- 2.6 addSectionNoCustom
- 2.7 disableCustomContexts
- 2.8 addHint
- 2.9 addGlobal
- 2.10 addInclude
- 2.11 spliceInclude
- 2.12 addSwitch
- 2.13 addExec
- 2.1 add
- 3 Dialplan Commands
Introduction
The Extensions class is not included by any module. It is passed during Apply Config changes to the BMO function BMO Hooks#DialplanHooks or <moduleraw>_get_config if using functions.inc.php
Core Methods
add
Add a new entry to the extensions_additional file
/** Add an entry to the extensions file
* @param $section The section to be added to
* @param $extension The extension used
* @param $tag A tag to use (to reference with basetag), use false or '' if none
* @param $command The command to execute
* @param $basetag The tag to base this on. Only used in conjunction with $addpriority
* priority. Defaults to false.
* @param $addpriority Finds the priority of the tag called $basetag, and adds this
* value to it to use as the priority for this command.
* @return
*/
function add($section, $extension, $tag, $command, $basetag = false, $addpriority = false) |
Example
PHP
$ext->add('vmx, '555', '', new ext_noop('Timeout: going to timeout dest'));
$ext->add('vmx, '555', '', new ext_noop('Foo: Bar')); |
extensions_additional
[my-context]
exten => 5555,1,Noop(Timeout: going to timeout dest)
exten => 5555,n,Noop(Foo: Bar) |
splice
Example
PHP
extensions_additional
PHP
extensions_additional
replace
remove
addSectionComment
addSectionNoCustom
disableCustomContexts
addHint
addGlobal
addInclude
spliceInclude
addSwitch
addExec
Dialplan Commands
gosub
Jump to label, saving return address.
Jumps to the label specified, saving the return address.
Gosub - Asterisk Documentation
Example
PHP
extensions_additional
messagesend
Send a text message.
Send a text message. The body of the message that will be sent is what is currently set to MESSAGE(body)
. The technology chosen for sending the message is determined based on a prefix to the to
parameter.
MessageSend - Asterisk Documentation
Example
PHP
extensions_additional
return
Return from gosub routine.
Jumps to the last label on the stack, removing it. The return value, if any, is saved in the channel variable GOSUB_RETVAL
.
Return - Asterisk Documentation
stackpop
Remove one address from gosub stack.
Removes last label on the stack, discarding it.
StackPop - Asterisk Documentation
gosubif
Conditionally jump to label, saving return address.
If the condition is true, then jump to labeliftrue. If false, jumps to labeliffalse, if specified. In either case, a jump saves the return point in the dialplan, to be returned to with a Return.
GosubIf - Asterisk Documentation
stasis
Invoke an external Stasis application.
Invoke a Stasis application.
Stasis - Asterisk Documentation
goto
Jump to a particular priority, extension, or context.
This application will set the current context, extension, and priority in the channel structure. After it completes, the pbx engine will continue dialplan execution at the specified location. If no specific extension, or extension and context, are specified, then this application will just set the specified priority of the current extension.
At least a priority is required as an argument, or the goto will return a -1
,and the channel and call will be terminated.
If the location that is put into the channel information is bogus, and asterisk cannot find that location in the dialplan, then the execution engine will try to find and execute the code in the i
(invalid) extension in the current context. If that does not exist, it will try to execute the h
extension. If neither the h
nor i
extensions have been defined, the channel is hung up, and the execution of instructions on the channel is terminated. What this means is that, for example, you specify a context that does not exist, then it will not be possible to find the h
or i
extensions, and the call will terminate!
gotoif
Conditional goto.
This application will set the current context, extension, and priority in the channel structure based on the evaluation of the given condition. After this application completes, the pbx engine will continue dialplan execution at the specified location in the dialplan. The labels are specified with the same syntax as used within the Goto application. If the label chosen by the condition is omitted, no jump is performed, and the execution passes to the next instruction. If the target location is bogus, and does not exist, the execution engine will try to find and execute the code in the i
(invalid) extension in the current context. If that does not exist, it will try to execute the h
extension. If neither the h
nor i
extensions have been defined, the channel is hung up, and the execution of instructions on the channel is terminated. Remember that this command can set the current context, and if the context specified does not exist, then it will not be able to find any 'h' or 'i' extensions there, and the channel and call will both be terminated!.
GotoIf - Asterisk Documentation
gotoiftime
Conditional Goto based on the current time.
This application will set the context, extension, and priority in the channel structure based on the evaluation of the given time specification. After this application completes, the pbx engine will continue dialplan execution at the specified location in the dialplan. If the current time is within the given time specification, the channel will continue at labeliftrue. Otherwise the channel will continue at labeliffalse. If the label chosen by the condition is omitted, no jump is performed, and execution passes to the next instruction. If the target jump location is bogus, the same actions would be taken as for Goto
. Further information on the time specification can be found in examples illustrating how to do time-based context includes in the dialplan.
GotoIfTime - Asterisk Documentation
while
endwhile
exitwhile