Documentation ¶
Overview ¶
Package dialplan facilitates the programmatic creation of asterisk dialplans.
The asterisk documentation overloads the term "expression" with various meanings. In this package an "expression" is any dialplan code that can be evaluated to produce a result. This package uses the term "operation" to describe expressions that involve an operator.
Example ¶
package main import ( "bytes" "fmt" "github.com/scjalliance/astconf" . "github.com/scjalliance/astconf/dialplan" ) // Employee holds contact information for Slate Rock and Gravel Company // personnel. type Employee struct { Number string Name string Phone Device } func main() { section := Section{Context: "slate-employees"} users := []Employee{ {Number: "100", Name: "Fred Flintstone", Phone: SIP("fred.flintstone")}, {Number: "101", Name: "Barney Rubble", Phone: SIP("barney.rubble")}, } for _, user := range users { section.Extensions = append(section.Extensions, Extension{ Comment: user.Name, Number: user.Number, Actions: []Action{ Noop(fmt.Sprintf("Call %s", user.Name)), ExecIf(Equal(DeviceState(user.Phone), String("NOT_INUSE")), Dial(user.Phone, 20)), Congestion(), }, }) } var buf bytes.Buffer e := astconf.NewEncoder(&buf) err := e.Encode(§ion) if err != nil { fmt.Println(err) } else { fmt.Print(buf.String()) } }
Output: [slate-employees] ; Fred Flintstone exten => 100,1,Noop(Call Fred Flintstone) same => n,ExecIf($[${DEVICE_STATE(SIP/fred.flintstone)}=NOT_INUSE]?Dial(SIP/fred.flintstone,20)) same => n,Congestion() ; Barney Rubble exten => 101,1,Noop(Call Barney Rubble) same => n,ExecIf($[${DEVICE_STATE(SIP/barney.rubble)}=NOT_INUSE]?Dial(SIP/barney.rubble,20)) same => n,Congestion()
Index ¶
- type Action
- type AppCall
- type Application
- type BinaryOp
- func Equal(e1 Expression, e2 Expression) BinaryOp
- func GreaterThan(e1 Expression, e2 Expression) BinaryOp
- func GreaterThanOrEqual(e1 Expression, e2 Expression) BinaryOp
- func LessThan(e1 Expression, e2 Expression) BinaryOp
- func LessThanOrEqual(e1 Expression, e2 Expression) BinaryOp
- func NotEqual(e1 Expression, e2 Expression) BinaryOp
- type CallerIDFunc
- type CongestionApp
- type Device
- type DeviceStateFunc
- type DialApp
- type ExecIfApp
- type ExprDef
- type ExprKind
- type Expression
- type Extension
- type FuncCall
- type Function
- type GosubApp
- type HangupApp
- type IfFunc
- type Int
- type LenFunc
- type MacroApp
- type MultiOp
- type NoopApp
- type PageApp
- type PlaybackApp
- type PresenceStateFunc
- type Quoteable
- type Reference
- type SIPAddHeaderApp
- type Section
- type SetApp
- type String
- type Var
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppCall ¶
type AppCall struct { Name string Args []string TrueArgs []string // Args presented after a "?" character FalseArgs []string // Args presented after a ":" character }
AppCall is a dialplan application call.
type Application ¶
type Application interface {
App() AppCall
}
Application is an interface that can be evaluated by the dialplan as an application.
type BinaryOp ¶
type BinaryOp struct { E1 Expression E2 Expression Operator string }
BinaryOp is a binary operation on two expressions.
func GreaterThan ¶
func GreaterThan(e1 Expression, e2 Expression) BinaryOp
GreaterThan returns a greater-than operation.
func GreaterThanOrEqual ¶
func GreaterThanOrEqual(e1 Expression, e2 Expression) BinaryOp
GreaterThanOrEqual returns a greater-than-or-equal operation.
func LessThan ¶
func LessThan(e1 Expression, e2 Expression) BinaryOp
LessThan returns a less-than operation.
func LessThanOrEqual ¶
func LessThanOrEqual(e1 Expression, e2 Expression) BinaryOp
LessThanOrEqual returns a less-than-or-equal operation.
func NotEqual ¶
func NotEqual(e1 Expression, e2 Expression) BinaryOp
NotEqual returns an inequality operation.
type CallerIDFunc ¶
type CallerIDFunc struct {
DataType string
}
CallerIDFunc is a dialplan function that gets Caller ID data for the channel.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Function_CALLERID
func CallerID ¶
func CallerID(dataType string) CallerIDFunc
CallerID returns a dialplan function that gets Caller ID data for the channel.
func (CallerIDFunc) Expr ¶
func (f CallerIDFunc) Expr() ExprDef
Expr returns the caller ID function as an expression.
func (CallerIDFunc) Func ¶
func (f CallerIDFunc) Func() FuncCall
Func returns the assembled function call.
func (CallerIDFunc) QuotedContent ¶
func (f CallerIDFunc) QuotedContent() bool
QuotedContent returns true, which indicates that the function call shoud be wrapped in double quotes when compared.
func (CallerIDFunc) Ref ¶
func (f CallerIDFunc) Ref() string
Ref returns a reference to the caller ID function.
type CongestionApp ¶
type CongestionApp struct {
Timeout int // Number of seconds to play congestion before hanging up
}
CongestionApp is a dialplan application that signals congestion to the caller.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Congestion
func Congestion ¶
func Congestion() CongestionApp
Congestion returns a dialplan application that signals congestion to the caller.
func (CongestionApp) App ¶
func (app CongestionApp) App() AppCall
App returns the assembled application call.
type DeviceStateFunc ¶
type DeviceStateFunc struct {
Device Device
}
DeviceStateFunc is a device state function.
func DeviceState ¶
func DeviceState(device Device) DeviceStateFunc
DeviceState returns a device state function.
func (DeviceStateFunc) Expr ¶
func (f DeviceStateFunc) Expr() ExprDef
Expr returns the device state function as an expression.
func (DeviceStateFunc) Func ¶
func (f DeviceStateFunc) Func() FuncCall
Func returns the assembled function call.
func (DeviceStateFunc) Ref ¶
func (f DeviceStateFunc) Ref() string
Ref returns a reference to the device state function.
type DialApp ¶
DialApp is a dialplan application that dials other devices.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Dial
type ExecIfApp ¶
type ExecIfApp struct { Expression IfTrue Application IfFalse Application }
ExecIfApp is a dialplan application that conditionally executes other applications.
func ExecIf ¶
func ExecIf(expr Expression, app Application) ExecIfApp
ExecIf returns a dialplan application that conditionally executes other applications.
When expr is true, app will be executed.
func ExecIfElse ¶
func ExecIfElse(expr Expression, trueApp, falseApp Application) ExecIfApp
ExecIfElse returns a dialplan application that conditionally executes other applications.
When expr is true, trueApp will be executed.
When expr is false, falseApp will be executed.
type Expression ¶
type Expression interface {
Expr() ExprDef
}
Expression is an interface that can be evaluated by the dialplan as an expression.
type FuncCall ¶
type FuncCall struct { Name string Args []string TrueArgs []string // Args presented after a "?" character FalseArgs []string // Args presented after a ":" character }
FuncCall is a dialplan function call.
type Function ¶
type Function interface {
Func() FuncCall
}
Function is an interface that can be evaluated by the dialplan as a function.
type GosubApp ¶
type GosubApp struct { Context string Extension string Priority int // Should be >= 1 Args []string }
GosubApp is a dialplan application that invokes subroutines.
type HangupApp ¶
type HangupApp struct {
Cause string
}
HangupApp is a dialplan application that hangs up the calling channel.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Hangup
type IfFunc ¶
type IfFunc struct { Expression IfTrue Expression IfFalse Expression }
IfFunc is a dialplan function that conditionally evaluates expressions.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Function_IF
func If ¶
func If(expr Expression, retValue Expression) IfFunc
If returns a dialplan function that conditionally evaluates expressions.
When expr is true, retValue will be returned.
func IfElse ¶
func IfElse(expr Expression, trueValue, falseValue Expression) IfFunc
IfElse returns a dialplan function that conditionally evaluates expressions.
When expr is true, trueValue will be returned.
When expr is false, falseValue will be returned.
type LenFunc ¶
type LenFunc struct {
Value Expression
}
LenFunc is a dialplan function that returns the length of a string.
func Len ¶
func Len(value Expression) LenFunc
Len returns a dialplan function that returns the length of a string.
type MacroApp ¶
type MacroApp struct { Name string Args []Expression }
MacroApp is a deprecated dialplan application that invokes subroutines.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Macro
func Macro ¶
func Macro(name string, args ...Expression) MacroApp
Macro returns a macro application.
Macros are deprecated and should be avoided if possible. The preferred subroutine calling mechanism is gosub.
type MultiOp ¶
type MultiOp struct { Expressions []Expression Operator string }
MultiOp is a operation on two or more expressions.
func And ¶
func And(e1 Expression, e2 Expression, extra ...Expression) MultiOp
And returns a logical and operation for two or more expressions.
func Or ¶
func Or(e1 Expression, e2 Expression, extra ...Expression) MultiOp
Or returns a logical or operation for two or more expressions.
type NoopApp ¶
type NoopApp struct {
Text string
}
NoopApp is a dialplan application that does nothing.
type PageApp ¶
type PageApp struct { Recipients []Device FullDuplex bool // d: Enable two-way audio for all recipients Forward bool // !i: Forward the page to forwarded recipients Quiet bool // q: Don't present a paging beep to recipients Record bool // r: Record the page to a file InUse bool // !s: Include recipients with a phone state other than NOT_INUSE Announcement string // A: Play an announcement to all recipients AnnounceToCaller bool // x: Play an announcement to the caller as well Timeout int // Number of seconds to attempt a call before giving up }
PageApp is a dialplan application that pages a set of devices.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Page
type PlaybackApp ¶
PlaybackApp is a dialplan application that plays sound files.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Playback
func Playback ¶
func Playback(files ...string) PlaybackApp
Playback returns a dialplan application that plays sound files.
func (PlaybackApp) App ¶
func (app PlaybackApp) App() AppCall
App returns the assembled application call.
type PresenceStateFunc ¶
PresenceStateFunc is a dialplan function that retrieves presence state.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Function_PRESENCE_STATE
func PresenceState ¶
func PresenceState(provider, field string) PresenceStateFunc
PresenceState returns a dialplan function that retrieves presence state.
func (PresenceStateFunc) Expr ¶
func (f PresenceStateFunc) Expr() ExprDef
Expr returns the presence state function as an expression.
func (PresenceStateFunc) Func ¶
func (f PresenceStateFunc) Func() FuncCall
Func returns the assembled function call.
func (PresenceStateFunc) QuotedContent ¶
func (f PresenceStateFunc) QuotedContent() bool
QuotedContent returns true, which indicates that the function call shoud be wrapped in double quotes when compared.
func (PresenceStateFunc) Ref ¶
func (f PresenceStateFunc) Ref() string
Ref returns a reference to the presence state function.
type Quoteable ¶
type Quoteable interface {
QuotedContent() bool
}
Quoteable is an interface implemented by expressions that can request that their content should be wrapped in double quotes.
type Reference ¶
type Reference interface {
Ref() string
}
Reference is an interface that can be evaluated by the dialplan as a reference.
type SIPAddHeaderApp ¶
SIPAddHeaderApp is a dialplan application that adds a SIP header to outbound calls.
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_SIPAddHeader
func SIPAddHeader ¶
func SIPAddHeader(header, content string) SIPAddHeaderApp
SIPAddHeader returns a dialplan application that adds a SIP header to outbound calls.
func (SIPAddHeaderApp) App ¶
func (app SIPAddHeaderApp) App() AppCall
App returns the assembled application call.
type Section ¶
Section is a dialplan section with a common context.
func (*Section) SectionName ¶
SectionName returns the name of the voicemail context section.
type SetApp ¶
type SetApp struct { Name Reference Value Expression }
SetApp is a dialplan application that sets channel and function variables.
func Set ¶
func Set(name Reference, value Expression) SetApp
Set returns a dialplan application that sets channel and function variables.
Source Files ¶
- action.go
- appcall.go
- application.go
- binaryop.go
- callerid.go
- congestion.go
- device.go
- devicestate.go
- dial.go
- doc.go
- execif.go
- exprdef.go
- expression.go
- exprkind.go
- extension.go
- funccall.go
- function.go
- gosub.go
- hangup.go
- if.go
- int.go
- len.go
- macro.go
- multiop.go
- noop.go
- page.go
- playback.go
- presencestate.go
- reference.go
- section.go
- set.go
- sipaddheader.go
- string.go
- var.go