Asterisk - Dialplan

最後更新: 2015-07-22

 

 

Usage

exten => number,priority,application([parameter[,parameter2...]])

i.e.

exten => 6001,1,Dial(PJSIP/601,20)

 

 


Reload & Check

 

dialplan reload

dialplan show

 


Search order:

    Explicit extensions
    Pattern match extensions
    Includes
    Switches

 


 

X
0 to 9

Z
1 to 9

N
2 to 9

Character Sets
_6[34]XX
[1-468]

 

(.) at the end of a pattern matches one or more remaining characters
(!) character is similar to the period and matches zero or more

 


Matching on Caller ID

 

match based upon the Caller ID of the incoming channel by appending a forward slash to the dialed extension or pattern

exten => 306,1,NoOp()
same => n,Background(goodbye)
same => n,Hangup()
 
exten => 306/_101,1,NoOp()
same => n,Background(year)
same => n,Hangup()
 
exten => 306/_102,1,NoOp()
same => n,Background(beep)
same => n,Hangup()

 


Special Asterisk Dialplan Extensions

a: Assistant extension
e: Exception Catchall extension
h: Hangup extension
i: Invalid entry extension
o: Operator extension
s: Start extension
t: Response timeout extension
T: Absolute timeout extension

 


Concurrent calls limit on SIP trunk

GROUP([category])  - gets, sets or clears the channel group

* Each channel can only be member of exactly one group per category
* categories can be employed for more fine grained group management
* if category = empty you need to use GROUP() in your dialplan

Checking:

group show channels

GROUP_COUNT([groupname][@category]) -  function returns the number of concurrent calls on the given trunk group

   

Verbose() 與 NoOp()

Verbose("minimum verbosity level", "message to print")

* Asterisk prints everything to the console if your verbosity level is three or higher
  => NoOp() 才 Debug 到

Method

same = n,Set(GROUP()=trunkgroup)
same = n,Verbose(1, "**** Number of concurrent calls are ${GROUP_COUNT(trunkgroup)}")
same = n,GotoIf($[${GROUP_COUNT(trunkgroup)} > 2]?999)
.....
same = 999,Verbose(1, "*** Number of concurrent calls are ${GROUP_COUNT(trunkgroup)} over limit")
same = n,Set(DIALSTATUS=CHANUNAVAIL)

必須的 extensions.conf

 

extensions.conf

[general]

static=yes

; "dialplan save"
writeprotect=no

clearglobalvars=no

; User context is where entries from users.conf are registered.
userscontext=default

[globals]

[stdexten]
exten => _X.,50000(stdexten),NoOp(Start stdexten)
exten => _X.,n,Set(LOCAL(ext)=${EXTEN})
exten => _X.,n,Set(LOCAL(dev)=${ARG1})
exten => _X.,n,Set(LOCAL(cntx)=${ARG2})
exten => _X.,n,Set(LOCAL(mbx)=${ext}${IF($[!${ISNULL(${cntx})}]?@${cntx})})

exten => a,n,Return()

exten => s,1,NoOp("*** Context: default ***")
exten => s,n,Answer()
exten => s,n,Wait(1)
exten => s,n,Playback(hello-world)
exten => s,n,Wait(10)
exten => s,n,Hangup()

[default]
include => stdexten

 


Predefined Extension Names

 

Asterisk uses some extension names for special purposes:

    i : Invalid
    s : Start
    h : Hangup
    t : Timeout
    T : AbsoluteTimeout
    a : Asterisk extension
    o : Operator

s: Start extension

When an analog call comes into Asterisk, the call is sent to the s extension. The s extension is also used in macros.

Please note that the s extension is not a catch-all extension. It's simply the location that analog calls and macros begin. In our example above, it simply makes a convenient extension to use that can't be easily dialed from the Background() and WaitExten() applications.

Incoming calls are always placed in a context in the dialplan,
either one you specify in the channel configuration file, or the default context.

If no other match exist for the call within the context, the s extension is activated.

The "s" extension is used when there is no known called number in the context used.

The "s" extension is used when starting a call. It is also used when defining a macro.

a: Assistant extension

This extension is similar to the o extension, only it gets triggered when the caller presses the asterisk (*) key while recording a voice mail message. This is typically used to reach an assistant.

 


同時 Call

; 一個個 ring

exten => 1001,1,NoOp(Operator)
    same = n,Dial(PJSIP/509,15)
    same = n,Dial(PJSIP/510,15)
    same = n,Hangup

; 一齊 ring

exten => 1002,1,NoOp(Operator)
    same = n,Dial(PJSIP/509&PJSIP/510,20)
    same = n,Hangup


Hangup(<causecode>)

calling channel unconditionally and returns -1.

causecode

For SIP Connections

"404 Not found",
"484 Address incomplete"

 


Playback

exten => 1003,1,NoOp(testing)
    same = n,Playback(sorry_no_messages)
    same = n,Hangup

 

 


DOC

https://wiki.asterisk.org/wiki/display/AST/Special+Dialplan+Extensions

Creative Commons license icon Creative Commons license icon