File này được đặt trong thư mục /etc/asterisk/.
File extensions.conf là một trong những file hay dùng và quan trọng nhất trong Asterisk PBX - nó chứa dialplan. Vậy dialplan là gì? Dialplan, hay chúng ta có thể nói là “trái tim của hệ thống Asterisk”, định nghĩa Asterisk PBX sẽ xử lý các cuộc gọi đến và gọi đi, nó cũng chứa tất cả các extension numbers. Dialplan được chia làm các section gọi là contexts. Mỗi context chứa nhiều hơn một extensions. Vậy extension là gì? Extension là số điện thoại (telephone number), nó có thể là các numbers, các chữ hay cả hai. Mọi extension có một priority và một application. Với sự giúp đỡ của các contexts chúng ta có thể tổ chức dialplan.
Nói chung một dialplan trông như sau:
[general]
–> một số thiết lậpở đây
[globals]
–> định nghĩa một số biến cục bộ
[context1]
–>extension 1, priority 1, application
–>extension 1, priority 2, application
–> extension helpdesk, priority 1, application
…
[context2]
–> extension 999, priority 1, application
–> extension 999, priority 1, application
…
2. Các Contexts
2.1 [general]
Context đầu tiên trong extensions.conf là [general], 3 tuỳ chọn cấu hình có thể được thiết lập là:
static= yes | no - Hiện tại Chỉ tuỳ chọn Yes được thực thi, (cho nên thiết lập nó thành No sẽ không có ảnh hưởng gì) và nếu static=yes và writeprotect=no , thì bạn có thể save dialplan từ CLI command ‘save dialplan‘.
Sẽ chi tiết hơn về điều này trong phần tutorial tiếp theo về CLI commands. (CLI chính là interactive asterisk shell, tại đó bạn có thể a.o. thay đổi dialplan và save nó mà không fải thay đổi file extensions.conf.)
writeprotect = yes | no - Tuỳ chọn này là cần thiết nếu bạn muốn có khả năng save những thay đổi của dialplan từ CLI command.
autofallthrough=yes|no - Nếu tuỳ chọn này được thiết lập, sau khi kết thúc với những việc fải làm, Asterisk sẽ hang up cuộc gọi. Nếu không thiết lập, Asterisk sẽ đợi extension khác được gọi. Tuỳ chọn này fải được set thành yes.
2.2 [globals]
Trong context [globals] bạn có thể khai báo các biến của bạn, các biến này có thể được sử dụng sau trong các extensions. Chú ý rằng một tên biến toàn cục không phân biệt hoa thường, nên ${MYVAR} và ${mYvaR} là như nhau.
Cách để khai báo biến trong section [globals] là:
The_name_of_my_variable => The_variable’s_value
Ví dụ:
[general]
static=yes
writeprotect=no
[globals]
MyMusicOnHold => /mp3/Mozart.mp3
2.3 Các context cuộc gọi thực sự - “Real” call contexts
Ngoại trừ [general] và [globals] mọi context khác đều là các call contexts. Về cơ bản các contexts trông như sau:
[context_name]
exten => some_exten_number,priority,application(arg1,arg2,…)
exten => some_exten_number,priority,application,arg1|arg2…
exten => some_pattern,priority,application(arg1,arg2,…)
Nhưng mục đích của ‘context’ là gì? Trong một context, bạn có thể xây dựng được một IVR menu (Interactive Voice Response) bằng việc sử dụng các extensions, bạn có thể định nghĩa một context cụ thể cho từng bộ phận (Dept.) của công ty (Accounting, Support, .v.v)
Sử dụng các context khác nhau, đội Accounting sẽ gọi tới người chỉ đạo John của họ qua số 123, và đội support sẽ gọi tới trưởng bộ phận support ‘alice’ khi ấn 123.
Đội support có thể gọi ra ngoài, nhưng đội account thì chỉ giới hạn gọi nội bộ.
Hoặc là các cuộc gọi ra ngoài có thể được gửi tới một hàng đợi, trong khi các cuộc gọi nội bộ giữa các đồng nghiệp sẽ đến thẳng đối tượng mà không fải xếp hàng.
Với sự giúp đỡ của các contexts rất dễ dàng để quản lý các số điện thoại được cấp phát.
Ví dụ:
[general]
; …skip…
[globals]
; …skip…
[Helpdesk]
exten => 323206,1,Dial(SIP/Helpdesk_agent01)
; …skip…
[Accounting]
exten => 443307,1,Dial(IAX2/Accounting_agent01)
; …skip…
Ví dụ về IVR menu:
[default]
exten => steve,1,Dial(SIP/steve);
exten => mark,2,Dial(SIP/mark);
[mainmenu]
exten => s,1,Answer
exten => s,n,Background(thanks) ; “Thanks for calling press 1 for sales, 2 for support, …”
exten => s,n,WaitExten
exten => 1,1,Goto(submenu,s,1)
exten => 2,1,Hangup
[submenu]
exten => s,1,Ringing ; Make them comfortable with 2 seconds of ringback
exten => s,n,Wait,2
exten => s,n,Background(submenuopts) ; “Thanks for calling the sales ;department. Press 1 for steve, 2 for…”
exten => s,n,WaitExten
exten => 1,1,Goto(default,steve,1)
exten => 2,1,Goto(default,mark,2)
Bây giờ chúng ta sẽ xem xét những dòng trên có ý nghĩa như thế nào.
Tất cả các cuộc gọi đến mainmenu context, đầu tiên sẽ đến extension s. (tại sao ? Đọc tiếp và bạn sẽ tìm thấy câu trả lời ở bên dưới trong phần các extensions được định nghĩa trước)
exten => s,1,Ringing:
The first priority in this s extension is extension 1, this will just provide some ringing sound to the caller.
exten => s,n,Wait,2:
The second priority in extension s, is the wait application with parameter 2, which would just wait for 2 seconds, and as a result give ringing for 2 seconds before playing the audio file “submenuopts” to the caller as defined in the 3rd priority. (exten => s,n,Background(submenuopts))
exten => s,n,WaitExten:
The 4th priority will wait for the caller to enter some digits, (such as press 1 for steve, press 2 for mark), the keys pressed by the caller will be the new extension. (if the person presses 1, the call will go to extension 1, priority 1, if the person presses 2, the call would go to extension 2, priority 2)
Lets assume the caller pressed 2:
exten => 2,1,Goto(default,mark,2):
The caller pressed 2 and the call flow will now go to the default context, extension mark, priority 2.
exten => mark,2,Dial(SIP/mark);
In this last step, it would dial the sip user mark. (as defined in sip.conf)
3. Extension
Extension = Số điện thoại? Vâng,về cơ bản là Đúng. Có 3 loại extensions : litteral, predifined (định nghĩa trước) và pattern.
litteral extension có thể chứa trong tên của chúng: các số (0-9), các chữ A,B,C,D (một vài hardphones có những letters này) hay các letters (a-z). Tên extension có phân biệt hoa thường không? Có và Không. Chúng phân biệt hoa thường khi Asterisk phải match một user dialed extension với các extensions được định nghĩa trong một context. Các Extension name không phân biệt hoa thường khi bạn cố gắng định nghĩa 2 extensions (trong một context) với cùng một tên but different case (bạn không thể làm điều này).
Có một vài tên extension được định nghĩa trước:
- i - Invalid - không hợp lệ
- s - Start - Bắt đầu
- h - Hangup - Treo
- t - Timeout - Quá thời gian
- T - AbsoluteTimeout - thời gian time out
- o - Operator
Ví dụ:
some example
Nếu tên extension bắt đầu với ‘_‘, nó được coi như là pattern.
Đối với extension sử dụng pattern, một vài ký tự có ý nghĩa đặc biệt:
- X - bất cứ ký tự số nào từ 0-9
- Z - bất cứ ký tự số nào từ 1-9
- N - bất cứ ký tự số nào từ 2-9
- [12679] - bất cứ ký tự số nào trong ngoặc (trong ví dụ là: 1,2,6,7,9)
- . - (dot) wildcard, matches everything remaining
( _1234. - xâu bất kỳ bắt đầu với 1234 trừ bản thân 1234).
Note: Không dùng ‘_.‘, vì nó tương ứng với bất kỳ cái gì kể cả extensions tiền định nghĩa!!!
Example:
_359ZXXXXXX - This will match all dilaed extensions that start with 359, and are 10 digits long( including 359)
_0XXX. - This will match all dialed extensions that begin with 0 and are minimum 5 digits long (including 0)
So you can see that with help of patterns you can group calls as national, international or local, the only thing you must do is to write the pattern.
4. Other very useful stuff included in extensions.conf
4.1 ignorepad
Another option that can be set is ignorepat. This option instructs drivers
to not cancel dialtone upon receipt specified pattern:
Example:
ignorepat => 8 - dialtone will remain after pressing 8
4.2 switch
Switch option permits a server to share his dialplan with
another server (ServerA>ServerB). Note that reciprocal switch
statements are not allowed (ServerA>ServerB and ServerB>ServerA).
switch => IAX2/
Note that
of the remote server (
4.3 include
You can include all numbers from one context to another context. To do that use:
include => some_context_to_be_included
Except context you can include another configuration file. To do this you have to use ‘#include‘:
#include “some_file_to_be_included.conf”
http://www.asteriskguru.com/tutorials/extensions_conf.html
Không có nhận xét nào:
Đăng nhận xét