Quantcast
Channel: VOIP-info.org Wiki Changes
Viewing all articles
Browse latest Browse all 5767

Asterisk variables

$
0
0

Using Variables in Asterisk Dialplans

Asterisk can make use of global, shared and channel-specific variables for arguments to commands. Variables are referenced in the dialplan (extensions.conf) using the syntax

${foo:offset:length}

where foo is the name of the variable, offset is an optional field indicating which characters should be excluded, and length is an optional field indicating the number of characters from the offset to be returned (see "Substrings" below for details and examples). A variable name may be any alphanumeric string beginning with a letter. User-defined variable names are not case sensitive — ${FOO} and ${Foo} refer to the same variable — but Asterisk-defined variables are case-sensitive — ${EXTEN} works, but ${exten} doesn't.

There are four types of variables: global variables, shared variables, channel variables, and environment variables.
  • Global variables can be set either in the [globals] category of extensions.conf or by using the SetGlobalVar command. Once defined, they can be referenced by any channel at any time.
  • Shared variables are new in Asterisk 1.6 (however a backport is available for 1.4): Two (or more?) channels can gain full access with the help of Asterisk func SHARED to what otherwise would be a channel variable.
  • Channel variables are set using the Set command (previously "setvar"). Each channel gets its own variable space, so there is no chance of collisions between different calls, and the variable is automatically trashed when the channel is hungup.
  • Environment variables provide a means to access unix environment variables from within Asterisk. There's a list further down this page.
If you define a channel variable with the same name as a global variable (and remember: user-defined variable names are not case sensitive), references to that variable name will return the value of the channel variable. ...

Viewing all articles
Browse latest Browse all 5767

Trending Articles