README.variables 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. GENERAL ENHANCEMENTS TO EXTENSION LOGIC :
  2. QUOTING:
  3. exten => s,5,BackGround,blabla
  4. The parameter (blabla) can be quoted ("blabla"). In this case, a
  5. comma does not terminate the field.
  6. Also, characters special to variable substitution, expression evaluation, etc
  7. (see below), can be quoted. For example, to literally use a $ on the
  8. string "$1231", quote it with a preceding \. Special characters that must
  9. be quoted to be used, are [ ] $ " \. (to write \ itself, use \\).
  10. VARIABLES:
  11. Parameter strings can include variables. Variable names are arbitrary strings.
  12. They are stored in the respective channel structure.
  13. To set a variable to a particular value, do :
  14. ;exten => 1,2,SetVar,varname=value
  15. You can substitute the value of a variable everywhere using ${variablename}.
  16. For example, to stringwise append $lala to $blabla and store result in $koko,
  17. do:
  18. ;exten => 1,2,SetVar,koko=${blabla}${lala}
  19. There are also the following special variables:
  20. ${CALLERID} Caller ID
  21. ${CALLERIDNAME} Caller ID Name only
  22. ${CALLERIDNUM} Caller ID Number only
  23. ${EXTEN} Current extension
  24. ${CONTEXT} Current context
  25. ${PRIORITY} Current priority
  26. ${CHANNEL} Current channel name
  27. ${ENV(VAR)} Environmental variable VAR
  28. ${LEN(VAR)} String length of VAR (integer)
  29. ${EPOCH} Current unix style epoch
  30. ${DATETIME} Current date time in the format: YYYY-MM-DD_HH:MM:SS
  31. ${TIMESTAMP} Current date time in the format: YYYYMMDD-HHMMSS
  32. ${UNIQUEID} Current call unique identifier
  33. ${DNID} Dialed Number Identifier
  34. ${RDNIS} Redirected Dial Number ID Service
  35. ${HANGUPCAUSE} Asterisk hangup cause
  36. ${ACCOUNTCODE} Account code (if specified)
  37. ${SIPDOMAIN} SIP destination domain of an inbound call (if appropriate)
  38. There are two reference modes - reference by value and reference by name.
  39. To refer to a variable with its name (as an argument to a function that
  40. requires a variable), just write the name. To refer to the variable's value,
  41. enclose it inside ${}. For example, SetVar takes as the first argument
  42. (before the =) a variable name, so:
  43. ;exten => 1,2,SetVar,koko=lala
  44. ;exten => 1,3,SetVar,${koko}=blabla
  45. stores to the variable "koko" the value "lala" and to variable "lala" the
  46. value "blabla".
  47. In fact, everything contained ${here} is just replaced with the value of
  48. the variable "here".
  49. EXPRESSIONS:
  50. Everything contained inside a bracket pair prefixed by a $ (like $[this]) is
  51. considered as an expression and it is evaluated. Evaluation works similar to
  52. (but is done on a later stage than) variable substitution: the expression
  53. (including the square brackets) is replaced by the result of the expression
  54. evaluation. The arguments and operands of the expression MUST BE separated
  55. with spaces (take care NOT to leave ANY spaces between opening and closing
  56. square brackets and the first and last arguments).
  57. For example, after the sequence:
  58. exten => 1,1,SetVar,"lala=$[1 + 2]";
  59. exten => 1,2,SetVar,"koko=$[2 * ${lala}]";
  60. the value of variable koko is "6".
  61. Operators are listed below in order of increasing precedence. Operators
  62. with equal precedence are grouped within { } symbols.
  63. expr1 | expr2
  64. Return the evaluation of expr1 if it is neither an empty string
  65. nor zero; otherwise, returns the evaluation of expr2.
  66. expr1 & expr2
  67. Return the evaluation of expr1 if neither expression evaluates to
  68. an empty string or zero; otherwise, returns zero.
  69. expr1 {=, >, >=, <, <=, !=} expr2
  70. Return the results of integer comparison if both arguments are
  71. integers; otherwise, returns the results of string comparison
  72. using the locale-specific collation sequence. The result of each
  73. comparison is 1 if the specified relation is true, or 0 if the
  74. relation is false.
  75. expr1 {+, -} expr2
  76. Return the results of addition or subtraction of integer-valued
  77. arguments.
  78. expr1 {*, /, %} expr2
  79. Return the results of multiplication, integer division, or
  80. remainder of integer-valued arguments.
  81. expr1 : expr2
  82. The `:' operator matches expr1 against expr2, which must be a
  83. regular expression. The regular expression is anchored to the
  84. beginning of the string with an implicit `^'.
  85. If the match succeeds and the pattern contains at least one regu-
  86. lar expression subexpression `\(...\)', the string correspond-
  87. ing to `\1' is returned; otherwise the matching operator
  88. returns the number of characters matched. If the match fails and
  89. the pattern contains a regular expression subexpression the null
  90. string is returned; otherwise 0.
  91. Parentheses are used for grouping in the usual manner.
  92. The parser must be parsed with bison (bison is REQUIRED - yacc cannot
  93. produce pure parsers, which are reentrant)
  94. CONDITIONALS
  95. There is one conditional operator - the conditional goto :
  96. ;exten => 1,2,gotoif,condition?label1:label2
  97. If condition is true go to label1, else go to label2. Labels are interpreted
  98. exactly as in the normal goto command.
  99. "condition" is just a string. If the string is empty or "0", the condition
  100. is considered to be false, if it's anything else, the condition is true.
  101. This is designed to be used together with the expression syntax described
  102. above, eg :
  103. exten => 1,2,gotoif,$[${CALLERID} = 123456]?2|1:3|1
  104. Example of use :
  105. exten => s,2,SetVar,"vara=1"
  106. exten => s,3,SetVar,"varb=$[${vara} + 2]"
  107. exten => s,4,SetVar,"varc=$[${varb} * 2]"
  108. exten => s,5,GotoIf,"$[${varc} = 6]?99|1:s|6";