Monday, October 27, 2014

Asterisk quick tips 1

Quick asterisk tips part 1

1. variables

when using expressions and a variable may not exist enclose it in double quotes so it gets interpreted into valid code and doesn't thrown an error

So if the VAR variable doesn't exist this gets interpreted into ""="ENDED" which will be false.

2. variable as variable name

If you get to advanced asterisk there may be a case where you need a variable to be a variable name, here is how to check if it is set


in this example ARG3 is a variable that holds the name of the variable to check.

3. stackpop

when using subroutines you have to return() to go back to the calling location.  But inevitably there are cases where you don't want to return.  No problem, just use stackpop() to remove the return location and you can go wherever you want in the dialplan without worrying about memory issues tracking the return location which isn't needed.

4. Special extensions

Learn the asterisk special extensions available.  Specifically the T extension, it allows you to set the timeout for a call, but instead of the system just hanging up you can run dialplan code to handle the channel properly.

  • s - What to do when an extension context is entered (unless overridden by the low level channel interface) This is used in macros, and some special cases. "s" is not a generic catch-all wildcard extension.
  • i - What to do if an invalid extension is entered
  • h - The hangup extension, executed at hangup
  • t - What to do if nothing is entered in the requisite amount of time.
  • T - This is the extension that is executed when the 'absolute' timeout is reached. See "core show function TIMEOUT" for more information on setting timeouts.
  • e - This extension will substitute as a catchall for any of the 'i', 't', or 'T' extensions, if any of them do not exist and catching the error in a single routine is desired. The function EXCEPTION may be used to query the type of exception or the location where it occurred.


Post a Comment