dialplan

package
v0.0.0-...-eec0033 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 4 Imported by: 0

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(&section)
	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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action = Application

Action is a dialplan action.

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.

func (AppCall) String

func (call AppCall) String() string

String returns the invocation string for the application call.

FIXME: Sanitize the function name and arguments.

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 Equal

func Equal(e1 Expression, e2 Expression) BinaryOp

Equal returns an equality operation.

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.

func (BinaryOp) Expr

func (op BinaryOp) Expr() ExprDef

Expr returns the binary operation as an expression.

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 Device

type Device struct {
	Technology string // Channel Driver
	Resource   string
}

Device is an addressable resource within a channel.

func PJSIP

func PJSIP(resource string) Device

PJSIP returns a PJSIP device address.

func SIP

func SIP(resource string) Device

SIP returns a SIP device address.

func (Device) String

func (d Device) String() string

String returns a string representation of the device address.

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

type DialApp struct {
	Devices []Device
	Timeout int // Seconds
}

DialApp is a dialplan application that dials other devices.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Application_Dial

func Dial

func Dial(device Device, seconds int) DialApp

Dial returns a dial application that dials a single device.

func DialMany

func DialMany(devices []Device, seconds int) DialApp

DialMany returns a dial application that dials one or more devices.

func (DialApp) App

func (dial DialApp) App() AppCall

App returnes the assembled application call.

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.

func (ExecIfApp) App

func (app ExecIfApp) App() AppCall

App returns the assembled application call.

type ExprDef

type ExprDef struct {
	Content string
	Kind    ExprKind
}

ExprDef is a dialplan expresssion definition.

func (ExprDef) String

func (expr ExprDef) String() string

String returns the invocation string for the expression.

type ExprKind

type ExprKind int

ExprKind describes the kind of an expression.

const (
	Ref ExprKind = iota
	NumLit
	StringLit
	Op
)

Types of expressions.

type Expression

type Expression interface {
	Expr() ExprDef
}

Expression is an interface that can be evaluated by the dialplan as an expression.

type Extension

type Extension struct {
	Comment string
	Number  string
	Actions []Action
}

Extension is a dialplan extension.

func (Extension) MarshalAsterisk

func (exten Extension) MarshalAsterisk(e *astconf.Encoder) error

MarshalAsterisk marshals the extension to an asterisk encoder.

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.

func (FuncCall) String

func (call FuncCall) String() string

String returns the invocation string for the function call.

FIXME: Sanitize the function name and arguments.

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.

func Gosub

func Gosub(context, extension string, priority int, args ...string) GosubApp

Gosub returns a gosub application.

If context or extension are empty, they will be omitted.

func (GosubApp) App

func (gosub GosubApp) App() AppCall

App returns the assembled application call.

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

func Hangup

func Hangup() HangupApp

Hangup returns a dialplan application that hangs up the calling channel.

func (HangupApp) App

func (app HangupApp) App() AppCall

App returns the assembled application call.

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.

func (IfFunc) Expr

func (function IfFunc) Expr() ExprDef

Expr returns the function as an expression.

func (IfFunc) Func

func (function IfFunc) Func() FuncCall

Func returns the assembled function call.

type Int

type Int int

Int is a dialplan number value that is restricted to integers.

func (Int) Expr

func (v Int) Expr() ExprDef

Expr fulfills the expression interface.

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.

func (LenFunc) Expr

func (f LenFunc) Expr() ExprDef

Expr returns the presence state function as an expression.

func (LenFunc) Func

func (f LenFunc) Func() FuncCall

Func returns the assembled function call.

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.

func (MacroApp) App

func (macro MacroApp) App() AppCall

App returnes the assembled application call.

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.

func (MultiOp) Expr

func (op MultiOp) Expr() ExprDef

Expr returns the binary operation as an expression.

type NoopApp

type NoopApp struct {
	Text string
}

NoopApp is a dialplan application that does nothing.

func Noop

func Noop(text string) NoopApp

Noop returns a dialplan application that does nothing.

func (NoopApp) App

func (noop NoopApp) App() AppCall

App returns the assembled application call.

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

func Page

func Page(recipients ...Device) PageApp

Page returns a dialplan application that pages a set of devices.

func (PageApp) App

func (app PageApp) App() AppCall

App returns the assembled application call.

func (PageApp) Options

func (app PageApp) Options() string

Options returns the options string for the page.

type PlaybackApp

type PlaybackApp struct {
	Files    []string
	Skip     bool
	NoAnswer bool
}

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

type PresenceStateFunc struct {
	Provider string
	Field    string
}

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

type SIPAddHeaderApp struct {
	Header  string
	Content string
}

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

type Section struct {
	Context    string `astconf:"-"`
	Extensions []Extension
}

Section is a dialplan section with a common context.

func (*Section) SectionName

func (section *Section) SectionName() string

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.

func (SetApp) App

func (app SetApp) App() AppCall

App returns the assembled application call.

type String

type String string

String is a dialplan string value.

func (String) Expr

func (v String) Expr() ExprDef

Expr fulfills the expression interface.

type Var

type Var string

Var is a variable reference.

func (Var) Expr

func (v Var) Expr() ExprDef

Expr returns the variable as an expression.

func (Var) Ref

func (v Var) Ref() string

Ref returns the variable as a reference.

func (Var) String

func (v Var) String() string

String returns a string representation of the variable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL