I have been reading the <asterisk, the path to the future of the phone chn2> electronic document, but the more I see it, the more I see it. So after N + X times of Baidu, find this document:
[Separator]
========================================================== ==============
Http://skytony.spaces.live.com/blog/cns! 3adcaf7d549e5c1e! 209. Entry
The configuration file "extensions. conf" contains the asterisk dialing Scheme (Dial plan ). The main solution for controlling all its operations and implementing the process. It controls how incoming and outgoing calls are processed and routed. Here is where you configure the connection behavior. The content of "extensions. conf" is organized as a "section. It can be set and defined statically and executed as the context. The configuration section can be defined by the system administrator in general or globals. A special type of "contexts" is macros, Which is customized by users and named with the prefix "macro-". This is a reusable mode, just like the "process" in programming languages ". Each section in extensions. conf starts with the node name in. This makes extensions. conf very similar to the traditional INI files in the Windows world. New things in Asterisk v1.2: by default, a new option "autofallthrough" is set to "yes ". this setting changes the previous rules so that the suspended call is immediately terminated in case of busy, blocking. If you are writing an extension for IVR, you must use the "waitexten" application. [General] configure several settings at the top of the Extentions. conf file. [Globals] then, in the [globals] section, you can define global variables/constants and their initial values. Contexts and extensions after [general] and [globals], the rest of the Extentions. conf file is the definition of dialplan. Dialplan is composed of contexts sets. Each context is composed of a set of extensions. Extension mode when you define extension in context, you not only use text numbers, letters, but also match extension mode. One extension context can be nested with another content in context. See the following example in dimensions: Context "default ":
Extension description
101 Mark Spencer
102 wil meadows
0 Operator
Context "local ":
Extension description
_ 9 nxxxxxx local CILS
Include => "default"
Context "longdistance ":
Extension description
_ 91 nxxnxxxxxx long distance CILS
Include => "local" here we define three types of extension. The first type of content: default is allowed to call three Extension: Mark, Wil, and the operator. the second content: A local extension mode: allows you to call a 7-digit number (local call) and "default" context, which also allows you to call Mark, Wil, or operator. The third content: longdistance is an extended mode that allows long-distance calls. It also includes the above two modes (default and local) using the extended context, you can carefully control who use the billing service (internal, local calls, long distance) if a dial number matches multiple modes, you can refer to "Extended Mode sorting". When Asterisk receives a incoming call connection from a channel, asterisk queries the channel commands from the context definition. Context defines different command Sets Based on the extension you call. For example, if the user calls "123", context can provide a set of command sets to guide how to do it. If the user calls "9", context can provide another set of command sets to guide what to do, and context can provide a set of command sets to control any number starting with "555" that the user calls. Some types of friendly connections, such as incoming calls from external networks, do not call extension. In this case ,... for example, you have a channel named "zap/1" that connects to a phone handheld device in your office. Assume that the configuration file (Zapata. in conf), you define context = John for zap Channel 1. in this way, when you use the handheld device to call a number, asterisk is in extension. in Conf, find the context named "John" and find out what it should do (work ). In extensions. conf defines a context named John, which should start with the following: [John] each context, you need to define one or more extensions, asterisk is called for comparison based on different numbers. Each extension tells asterisk what to do through the command set list. Extensions extension has two types: literal and pattern literal extension can be a number, just like 123. It can also include the standard symbols * and # that appear in a traditional phone. Therefore, 12 #89 * is a valid extension. some dial numbers have some special DTMF keys labeled as A, B, C, or D. Extension can also be defined using these letters. In fact, the extension name can contain any letters, numbers, and some punctuation marks. Is the extension name case sensitive? Yes. Sometimes it is case sensitive, sometimes it is not. When users use their VOIP phone to call extension named "office", asterisk does not execute the commands defined in extension named "office. On the other hand, extension names are not case-sensitive, so you cannot define extension in a content only in case. therefore, you cannot define a set of assembly for "office" extension, and define a set of assembly for "office" extension. The predefined extension name. Asterisk specifies some extension names for specific targets.
- I: Invalid
- S: Start
- H: hangup
- T: timeout
- T: absolutetimeout
- O: Operator
Details:Asterisk standard extensions
Define Extension
Unlike traditional PBX, extension is associated with telephones, interfaces, menus, and so on. In asterisk, an extension is defined as a command execution list. Just like the dial and gotoif commands, they can be transferred to a certain place based on different conditions.
When an extension is called, the command marked as priority 1 is executed, followed by 2, and so on.
This will continue:
- The call is suspended.
- Command return code-1 (indicating failure)
- The next command with a higher priority does not exist. (Note: asterisk will not skip the lost priority level)
- The call is routed to a new extension.
Syntax in the extension. conf file. Each step of an extension execution is in the following format:
Exten = extension, priority, command (parameters)
Here, the equal sign can also be modified with an arrow, that is, "=>", a format that is often seen in many examples.
Well, let's assume a "context" named "John ". In each context, you can define one or more extension. In each extension, you define a set of command sets. How do you define these extension and commands? You need a text editor to edit the extensions. conf file. Of course, you can also use some good tools:GUI tool.
The execution steps and command line components in extension are as follows:
- ExtensionIt is an extension tag, which can be a String constant or a dynamic pattern-matching many possible phone numbers.
- PriorityIt is usually a positive number (for special cases, see note ). It is the sorting number of each command line in the extension. The priority value of the first executable command is "1 ". Therefore, when Asterisk transfers a call to an extension, it first looks for a command with a priority value of 1. If there is no row with a priority of 1, the extension will not match the dial number. After the command with priority 1 is executed, asterisk increases the value of priority to 2 unless the command determines the next priority value to be executed. If the extension does not define the next priority, asterisk will complete the processing of this extension, even if there is a command with a higher priority than the loss of the command.
Note: In special cases, strings are also used to specify the priority (seeAsterisk standard extensions).
- CommandIs the name of the command (also known as "application "). For details, seeAsterisk commands list.
- ParametersDepends on commands. Some commands have no parameters. In this case, the parameters are omitted.
Example
Exten => 123,1, answer
Exten => 123,2, playback (TT-weasels)
Exten => 123,3, voicemail (44)
Exten => 123,4, hangup
This is the definition of a single extension named "123. However, when a call is scheduled to extension 123, asterisk will answer the call by itself, play a sound file named "TT-Weasels", prompt the user to leave a voice mail, and then stop the call.
It should be noted that asterisk does not pay attention to the order of these lines of code in the extensions. conf file. You can mix these lines of code in different order, as in the following example, it is no different from the previous example, because asterisk usesPriorityTo indicate the execution sequence of each row.
Exten => 123,4, hangup
Exten => 123,1, answer
Exten => 123,3, voicemail (44)
Exten => 123,2, playback (TT-weasels)
Other options when defining extension include options called "ex-girlfriend" logic. This logic will match extension. Whether it is external or internal, the key is to check the caller's call ID (Caller ID). For example:
Exten = & gt; 123/100, 1, answer ()
Exten = & gt; 123/100, 2, playback (TT-weasels)
Exten => 123/100, 3, voicemail (123)
Exten = & gt; 123/100, 4, hangup ()
This extension is matched only when the ID of the caller is 100 and the following options are executed. This can also be done through pattern matching, as shown below:
Exten => 1234/_ 256 nxxxxxx, 1, answer ()
And so on...
Only caller IDs starting with 256 match the "1234" pattern. This is useful in keeping local calls.
You can even do the following:
Exten => S, 1, answer
Exten => S/9184238080,2, set (callerid (name) = edevil bastard)
Exten => S, 2, set (callerid (name) = Good Person)
Exten => S, 3, dial (Sip/Goodperson)
Syntax keywords for defining context include exten, include, ignorepat, and switch.
For details, see:How does asterisk handle "match as you go" dialing?
One drawback of this extension sorting method is that if you want to insert or delete a priority, you must manually re-enter all numbers. I am working on a tool to deal with this issue. If you are interested, try it:Give it a try
In Versions later than asterisk1.2, there is a new method to handle this issue. The first priority is assigned to it, and the next priority is named "N". For more information, see:Asterisk priorities
Variables and expressions
Variable Structure $ {variablename}
Use the expression structure $ {expression}. Here the expression can be a common expression, a comparison expression, an addition expression, and so on.
For standard variables, see:Asterisk Variables. For the expression description, see:Asterisk readme. Variables
For more information about global variables and channel variables in the extensions. conf file, seeUsing variables in Asterisk dialplans
For the new dialing function in version 1.2, see:Using Functions in Asterisk dialplans
Load
If you want to reload the dialing scheme after the setting has changed, you do not need to load all the asterisk configuration files. You can use extension to load the command:Asterisk CLI
Is there a large file or a few small files?
When used in the extension. conf file# Include <FILENAME>The statement contains other files. In this way, you can start such a system: extensions. conf is the main file,Users. confInclude your local user,Services. confContains various services, such as the conference system. Using this method, the dialing scheme may be easier to maintain.# Include <FILENAME>Statement is different fromInclude <context>Statement.# IncludeThe declaration can be used in all configuration files.
To another Asterisk
Syntax:
[Iaxprovider]
Switch => iax2/User: [Key] @ server/Context
To another server.UserAndKeyIt must be defined in the IAX. conf file of the incoming server.
ContextIs the context in the extensions. conf file of the server to be transferred.
Example:Asterisk-Dual Servers
Extensions. conf
Asterisk extensions from MySQL
All. conf files can use the # include declaration to include another. conf file.
Example:
# Include "My-extra-config-file"
[Globals]
All = zap/1 & Sip/1000 & Sip/1001
[Default]
Exten => S, 1, answer
Exten => S, 2, playback (welcome-message)
Exten => S, 3, Goto (context-in-include-file, S, 1); context defined in the go to include file
:
:
Example:
Use macro to create Extension
[Globals]
Phone1 = zap/1
Phone2 = Sip/6002
[Macro-oneline]
Exten => S, 1, dial ($ {arg1}, 20, T)
Exten => S, 2, voicemail (U $ {macro_exten })
Exten => S, 3, hangup
Exten => S, 102, voicemail (B $ {macro_exten })
Exten => S, 103, hangup
[Local]
Exten => 6601,1, macro (oneline, ${phone1 })
Exten => 6602,1, macro (oneline, ${phone2 })