ari

package module
v2.0.0-...-7e58b63 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2016 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MuteIn   = "in"
	MuteOut  = "out"
	MuteBoth = "both"
)

Mute-related constants for use with the mute commands `MuteIn` mutes audio coming in to the channel from Asterisk `MuteOut` mutes audio coming out from the channel to Asterisk `MuteBoth` mutes audio in both directions

View Source
const (
	// RecordInProgress indicates that a recording is still in progress
	RecordInProgress = iota

	// RecordCanceled indicates that a recording was canceled (by request)
	RecordCanceled

	// RecordFailed indicates that a recording failed
	RecordFailed

	// RecordFinished indicates that a recording finished normally
	RecordFinished

	// RecordHangup indicates that a recording was ended due to hangup
	RecordHangup
)
View Source
const ALL string = "all"

ALL signifies that the subscriber wants all events

View Source
const AST_CAUSE_ACCESS_INFO_DISCARDED = 43
View Source
const AST_CAUSE_ANSWERED_ELSEWHERE = 26
View Source
const AST_CAUSE_BEARERCAPABILITY_NOTAUTH = 57
View Source
const AST_CAUSE_BEARERCAPABILITY_NOTAVAIL = 58
View Source
const AST_CAUSE_BEARERCAPABILITY_NOTIMPL = 65
View Source
const AST_CAUSE_CALL_AWARDED_DELIVERED = 7
View Source
const AST_CAUSE_CALL_REJECTED = 21
View Source
const AST_CAUSE_CHANNEL_UNACCEPTABLE = 6
View Source
const AST_CAUSE_CHAN_NOT_IMPLEMENTED = 66
View Source
const AST_CAUSE_DESTINATION_OUT_OF_ORDER = 27
View Source
const AST_CAUSE_FACILITY_NOT_IMPLEMENTED = 69
View Source
const AST_CAUSE_FACILITY_NOT_SUBSCRIBED = 50
View Source
const AST_CAUSE_FACILITY_REJECTED = 29
View Source
const AST_CAUSE_IE_NONEXIST = 99
View Source
const AST_CAUSE_INCOMING_CALL_BARRED = 54
View Source
const AST_CAUSE_INCOMPATIBLE_DESTINATION = 88
View Source
const AST_CAUSE_INTERWORKING = 127
View Source
const AST_CAUSE_INVALID_CALL_REFERENCE = 81
View Source
const AST_CAUSE_INVALID_IE_CONTENTS = 100
View Source
const AST_CAUSE_INVALID_MSG_UNSPECIFIED = 95
View Source
const AST_CAUSE_INVALID_NUMBER_FORMAT = 28
View Source
const AST_CAUSE_MANDATORY_IE_LENGTH_ERROR = 103
View Source
const AST_CAUSE_MANDATORY_IE_MISSING = 96
View Source
const AST_CAUSE_MESSAGE_TYPE_NONEXIST = 97
View Source
const AST_CAUSE_MISDIALLED_TRUNK_PREFIX = 5
View Source
const AST_CAUSE_NETWORK_OUT_OF_ORDER = 38
View Source
const AST_CAUSE_NORMAL_CIRCUIT_CONGESTION = 34
View Source
const AST_CAUSE_NORMAL_CLEARING = 16
View Source
const AST_CAUSE_NORMAL_TEMPORARY_FAILURE = 41
View Source
const AST_CAUSE_NORMAL_UNSPECIFIED = 31
View Source
const AST_CAUSE_NO_ANSWER = 19
View Source
const AST_CAUSE_NO_ROUTE_DESTINATION = 3
View Source
const AST_CAUSE_NO_ROUTE_TRANSIT_NET = 2
View Source
const AST_CAUSE_NO_USER_RESPONSE = 18
View Source
const AST_CAUSE_NUMBER_CHANGED = 22
View Source
const AST_CAUSE_NUMBER_PORTED_NOT_HERE = 14
View Source
const AST_CAUSE_OUTGOING_CALL_BARRED = 52
View Source
const AST_CAUSE_PRE_EMPTED = 8
View Source
const AST_CAUSE_PROTOCOL_ERROR = 111
View Source
const AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE = 102
View Source
const AST_CAUSE_REDIRECTED_TO_NEW_DESTINATION = 23
View Source
const AST_CAUSE_REQUESTED_CHAN_UNAVAIL = 44
View Source
const AST_CAUSE_RESPONSE_TO_STATUS_ENQUIRY = 30
View Source
const AST_CAUSE_SUBSCRIBER_ABSENT = 20
View Source
const AST_CAUSE_SWITCH_CONGESTION = 42
View Source
const AST_CAUSE_UNALLOCATED = 1
View Source
const AST_CAUSE_USER_BUSY = 17
View Source
const AST_CAUSE_WRONG_CALL_STATE = 101
View Source
const AST_CAUSE_WRONG_MESSAGE = 98
View Source
const AllDTMF = "0123456789ABCD*#"

AllDTMF is a string which contains all possible DTMF digits.

View Source
const AsteriskDateFormat = "2006-01-02T15:04:05.000-0700"

Variables

View Source
var (
	DefaultUsername = "ariTest"
	DefaultSecret   = "ariDev"
)
View Source
var (
	// ExistsFail indicates that a recording should fail if the
	// given name already exists.
	ExistsFail = "fail"

	// ExistsOverwrite indicates that if a recording exists of
	// the same name, it should be overwritten.
	ExistsOverwrite = "overwrite"

	// ExistsAppend indicates that if a recording exists of the
	// same name, it should be appended to.
	ExistsAppend = "append"
)
View Source
var (
	// TerminateNever indicates that a recording should not be
	// ended on any DTMF tone.
	TerminateNever = "none"

	// TerminateAny indicates that a recording should be terminated
	// if any DTMF digit is received
	TerminateAny = "any"

	// TerminateStar indicates that a recording should be terminated
	// if a * DTMF character is received.
	TerminateStar = "*"

	// TerminateHash indicates that a recording should be terminated
	// if a # DTMF character is received.
	TerminateHash = "#"

	// TerminatePound indicates that a recording should be terminated
	// if a # DTMF character is received.
	TerminatePound = "#"
)
View Source
var AsteriskCodec = websocket.Codec{
	Marshal:   marshal,
	Unmarshal: unmarshal,
}

AsteriskCode is a websocket Codec for Asterisk messages

View Source
var BusChannelBuffer = 100

BusChannelBuffer defines the buffer size of the subscription channels

View Source
var DefaultClient = NewClient(&Options{
	Application: "default",
	Username:    "ariTest",
	Password:    "ariDev",
})
View Source
var Logger = log15.New()

Logger

Logger defaults to a discard handler (null output). If you wish to enable logging, you can set your own handler like so:

ari.Logger.SetHandler(log15.StderrHandler)
View Source
var MaxIdleConnections = 20

MaxIdleConnections is the maximum number of idle web client connections to maintain.

View Source
var MaxPlaybackTime = 10 * time.Minute

MaxPlaybackTime is the maximum amount of time to allow for a playback to complete.

View Source
var PlaybackStartTimeout = 1 * time.Second

PlaybackStartTimeout is the time to allow for Asterisk to send the PlaybackStarted before giving up.

View Source
var RecordingStartTimeout = 1 * time.Second

RecordingStartTimeout is the amount of time to wait for a recording to start before declaring the recording to have failed.

View Source
var RequestTimeout = 2 * time.Second

RequestTimeout describes the maximum amount of time to wait for a response to any request.

Functions

func CodeFromError

func CodeFromError(err error) int

CodeFromError extracts and returns the code from an error, or 0 if not found.

func IsOpenPattern

func IsOpenPattern(p string) bool

IsOpenPattern determines whether the regular expression is open-ended (allows for an indeterminite number of trailing parts) or not.

func NewBridgeContext

func NewBridgeContext(ctx context.Context, b *Bridge) context.Context

NewBridgeContext returns a context with the bridge attached

func NewBridgeContextWithKey

func NewBridgeContextWithKey(ctx context.Context, b *Bridge, name string) context.Context

NewBridgeContextWithKey returns a context with the bridge attached as the given key

func NewChannelContext

func NewChannelContext(ctx context.Context, c *Channel) context.Context

NewChannelContext returns a context with the channel attached

func NewChannelContextWithKey

func NewChannelContextWithKey(ctx context.Context, c *Channel, name string) context.Context

NewChannelContext returns a context with the channel attached as the given key

func NewClientContext

func NewClientContext(ctx context.Context, c *Client) context.Context

NewClientContext returns a context with the client attached

func NewClientContextWithKey

func NewClientContextWithKey(ctx context.Context, c *Client, name string) context.Context

NewClientContextWithKey returns a context with the client attached as the given key

func Play

func Play(ctx context.Context, p Player, mediaURI string) error

Play plays audio to the given Player, waiting for completion and returning any error encountered during playback.

Types

type AddChannelRequest

type AddChannelRequest struct {
	ChannelID string `json:"channel"`
	Role      string `json:"role,omitempty"`
}

AddChannelRequest is the structure to add a channel to a bridge. Only Channel is required. ChannelID field allows for comma-separated-values to add multiple channels.

type Application

type Application struct {
	BridgeIDs   []string `json:"bridge_ids"`   // Subscribed BridgeIds
	ChannelIDs  []string `json:"channel_ids"`  // Subscribed ChannelIds
	DeviceNames []string `json:"device_names"` // Subscribed Device names
	EndpointIDs []string `json:"endpoint_ids"` // Subscribed Endpoints (tech/resource format)
	Name        string   `json:"name"`         // Name of the application
}

Application describes a Stasis (Ari) application

type ApplicationReplaced

type ApplicationReplaced Event

ApplicationReplaced is a notification to the original application that notifications about this application are now going to a different WebSocket connection. There can only be a single websocket connection for each application at any given time.

type AsteriskDate

type AsteriskDate time.Time

Asterisk ARI does not supply a format that the built-in golang json date parser can use, so we have to write our own unmarshal routine for it

func (AsteriskDate) MarshalJSON

func (d AsteriskDate) MarshalJSON() ([]byte, error)

func (AsteriskDate) String

func (d AsteriskDate) String() string

func (*AsteriskDate) UnmarshalJSON

func (d *AsteriskDate) UnmarshalJSON(data []byte) error

type AsteriskInfo

type AsteriskInfo struct {
	BuildInfo  BuildInfo  `json:"build"`
	ConfigInfo ConfigInfo `json:"config"`
	StatusInfo StatusInfo `json:"status"`
	SystemInfo SystemInfo `json:"system"`
}

AsteriskInfo describes a running asterisk system

type Bridge

type Bridge struct {
	ID         string   `json:"id"`          // Unique Id for this bridge
	Class      string   `json:"bridge"`      // Class of the bridge (TODO: huh?)
	Type       string   `json:"bridge_type"` // Type of bridge (mixing, holding, dtmf_events, proxy_media)
	ChannelIDs []string `json:"channels"`    // List of pariticipating channel ids
	Creator    string   `json:"creator"`     // Creating entity of the bridge
	Name       string   `json:"name"`        // The name of the bridge
	Technology string   `json:"technology"`  // Name of the bridging technology
	// contains filtered or unexported fields
}

Bridge describes an Asterisk Bridge, the entity which merges media from one or more channels into a common audio output

func BridgeFromContext

func BridgeFromContext(ctx context.Context) (*Bridge, bool)

BridgeFromContext returns the default Bridge stored in the context

func BridgeFromContextWithKey

func BridgeFromContextWithKey(ctx context.Context, name string) (*Bridge, bool)

BridgeFromContextWithKey returns the Bridge stored in the context

func (*Bridge) Add

func (b *Bridge) Add(channelID string) error

Add adds a channel to the bridge

func (*Bridge) AttachClient

func (b *Bridge) AttachClient(a *Client)

AttachClient attaches the provided ARI client to the bridge

func (*Bridge) Delete

func (b *Bridge) Delete() error

Delete destroys the bridge

func (*Bridge) GetClient

func (b *Bridge) GetClient() *Client

GetClient returns the ARI client which created the bridge

func (*Bridge) GetID

func (b *Bridge) GetID() string

GetID returns the ID of this bridge

func (*Bridge) Play

func (b *Bridge) Play(mediaURI string) (string, error)

Play plays an audio uri to a bridge, returning its playback ID

func (*Bridge) PlayWithID

func (b *Bridge) PlayWithID(id, mediaURI string) error

PlayWithID plays an audio uri to the bridge with the provided playback ID

func (*Bridge) Record

func (b *Bridge) Record(name string, opts *RecordingOptions) (*LiveRecording, error)

Record starts recording the audio from a bridge to the given recording name.

func (*Bridge) Remove

func (b *Bridge) Remove(channelID string) error

Remove removes a channel from the bridge

type BridgeAttendedTransfer

type BridgeAttendedTransfer struct {
	Event
	DestinationApplication     string  `json:"destination_application,omitempty"`
	DestinationBridge          string  `json:"desination_bridge,omitempty"`
	DestinationLinkFirstLeg    Channel `json:"destination_link_first_leg,omitempty"`
	DestinationLinkSecondLeg   Channel `json:"destination_link_second_leg,omitempty"`
	DestinationThreewayBridge  Bridge  `json:"destination_threeway_bridge,omitempty"`
	DestinationThreewayChannel Channel `json:"destination_threeway_channel,omitempty"`
	DestinationType            string  `json:"destination_type"`
	External                   bool    `json:"is_external"`
	Result                     string  `json:"result"`
	Transferee                 Channel `json:"transferee,omitempty"`
	TransferTarget             Channel `json:"transfer_target,omitempty"`
	TransfererFirstLeg         Channel `json:"transferer_first_leg"`
	TransfererFirstLegBridge   Bridge  `json:"transferer_first_leg_bridge,omitempty"`
	TransfererSecondLeg        Channel `json:"transferer_second_leg"`
	TransfererSecondLegBridge  Bridge  `json:"transferer_second_leg_bridge,omitempty"`
}

BridgeAttendedTransfer events signify that an attended transfer has occurred

type BridgeBlindTransfer

type BridgeBlindTransfer struct {
	Event
	Bridge         Bridge  `json:"bridge,omitempty"`
	Channel        Channel `json:"channel"`
	Context        string  `json:"context"`
	Extension      string  `json:"exten"`
	External       bool    `json:"external"`
	ReplaceChannel Channel `json:"external,omitempty"`
	Result         string  `json:"result"`
	Transferee     Channel `json:"transferee,omitempty"`
}

BridgeBlindTransfer events signify that a blind transfer has occurred

type BridgeCreated

type BridgeCreated struct {
	Event
	Bridge Bridge `json:"bridge"`
}

BridgeCreated events indicate a bridge has been created

type BridgeDestroyed

type BridgeDestroyed struct {
	Event
	Bridge Bridge `json:"bridge"`
}

BridgeDestroyed events indicate a bridge has been destroyed

type BridgeEvent

type BridgeEvent struct {
	Event
	Bridge Bridge `json:"bridge,omitempty"` // Affected bridge
}

BridgeEvent (meta) is an event which affects a bridge

type BridgeMerged

type BridgeMerged struct {
	Event
	Bridge      Bridge `json:"bridge"`      // New bridge
	Bridge_from Bridge `json:"bridge_from"` // Old (independant) bridge -- TODO: verify this assumption
}

BridgeMerged events indicate a bridge has been merged into another (bridge)

type BuildInfo

type BuildInfo struct {
	Date    string `json:"date"`
	Kernel  string `json:"kernel"`
	Machine string `json:"machine"`
	Options string `json:"options"`
	Os      string `json:"os"`
	User    string `json:"user"`
}

BuildInfo describes information about how Asterisk was built

type Bus

type Bus struct {
	// contains filtered or unexported fields
}

Bus is an event bus for ARI events. It receives and redistributes events based on a subscription model.

func StartBus

func StartBus(ctx context.Context) *Bus

StartBus creates and returns the event bus.

func (*Bus) Once

func (b *Bus) Once(ctx context.Context, eTypes ...string) <-chan Eventer

Once listens for the first event of the provided types, returning a channel which supplies that event.

func (*Bus) Stop

func (b *Bus) Stop()

Stop the bus. Cancels all subscriptions and stops listening for events.

func (*Bus) Subscribe

func (b *Bus) Subscribe(eTypes ...string) *Subscription

Subscribe returns a subscription to the given list of event types

type CallerId

type CallerId struct {
	Name   string `json:"name"`
	Number string `json:"number"`
}

CallerId describes the name and number which identifies the caller to other endpoints

func (*CallerId) String

func (cid *CallerId) String() string

String returns the stringified callerid

type Channel

type Channel struct {
	Accountcode  string       `json:"accountcode"`
	Caller       CallerId     `json:"caller"`    // CallerId of the calling endpoint
	Connected    CallerId     `json:"connected"` // CallerId of the connected line
	Creationtime AsteriskDate `json:"creationtime"`
	Dialplan     DialplanCEP  `json:"dialplan"` // Current location in the dialplan
	Id           string       `json:"id"`       // Unique id for this channel (same as for AMI)
	Name         string       `json:"name"`     // Name of this channel (tech/name-id format)
	State        string       `json:"state"`    // State of the channel
	// contains filtered or unexported fields
}

Channel describes a(n active) communication connection between Asterisk and an Endpoint

func ChannelFromContext

func ChannelFromContext(ctx context.Context) (*Channel, bool)

ChannelFromContext returns the default Channel stored in the context

func ChannelFromContextWithKey

func ChannelFromContextWithKey(ctx context.Context, name string) (*Channel, bool)

ChannelFromContextWithKey returns the default Channel stored in the context

func (*Channel) Answer

func (c *Channel) Answer() error

Answer answers the current channel

func (*Channel) AttachClient

func (c *Channel) AttachClient(a *Client)

AttachClient attaches the provided ARI client to the channel

func (*Channel) Busy

func (c *Channel) Busy() error

Busy hangs up the current channel with the "busy" cause code

func (*Channel) Congestion

func (c *Channel) Congestion() error

Congestion hangs up the current channel with the "congestion" cause code

func (*Channel) Continue

func (c *Channel) Continue(context string, extension string, priority int64) error

Continue causes the current channel to continue in the dialplan

func (*Channel) Get

func (c *Channel) Get(name string) (string, error)

Get retrieves a channel variable from the channel

func (*Channel) GetClient

func (c *Channel) GetClient() *Client

GetClient returns the ARI client which created the channel

func (*Channel) GetID

func (c *Channel) GetID() string

GetID returns the ID of this channel

func (*Channel) Hangup

func (c *Channel) Hangup() error

Hangup hangs up the current channel

func (*Channel) Hold

func (c *Channel) Hold() error

Hold puts the channel on hold

func (*Channel) IsAnswered

func (c *Channel) IsAnswered() (bool, error)

IsAnswered checks the current state of the channel to see if it is "Up" (answered)

func (*Channel) IsReal

func (c *Channel) IsReal() bool

IsReal indicates whether the channel is "real" (not a local channel)

func (*Channel) MOH

func (c *Channel) MOH(mohClass string) error

MOH plays music on hold of the given class to the channel

func (*Channel) Mute

func (c *Channel) Mute(dir string) error

Mute mutes the channel in the given direction (one of "in", "out", or "both")

func (*Channel) Play

func (c *Channel) Play(mediaUri string) (string, error)

Play initiates playback of the specified media uri to the channel, returning the Playback's Id

func (*Channel) PlayWithID

func (c *Channel) PlayWithID(id, mediaUri string) error

PlayWithID initiates playback of the specified media uri with the provided playbackID to the channel.

func (*Channel) Record

func (c *Channel) Record(name string, opts *RecordingOptions) (*LiveRecording, error)

Record starts recording the channel, returning the LiveRecording

func (*Channel) Ring

func (c *Channel) Ring() error

Ring indicates ringing to the channel

func (*Channel) SendDTMF

func (c *Channel) SendDTMF(dtmf string) error

SendDTMF sends DTMF to the channel

func (*Channel) Set

func (c *Channel) Set(name string, value string) error

Set sets a channel variable of the channel

func (*Channel) Silence

func (c *Channel) Silence() error

Silence transmits silence (comfort noise) to the channel

func (*Channel) Snoop

func (c *Channel) Snoop() (string, error)

Snoop begins a snoop session and returns its id TODO: what is the channel being returned; do we need it?

func (*Channel) StopMOH

func (c *Channel) StopMOH() error

StopMOH stops playing of music on hold to the channel

func (*Channel) StopRing

func (c *Channel) StopRing() error

StopRing stops ringing on the channel

func (*Channel) StopSilence

func (c *Channel) StopSilence() error

StopSilence stops transmission of silence to channel

func (*Channel) Unhold

func (c *Channel) Unhold() error

Unhold retrieves the channel from hold

func (*Channel) Unmute

func (c *Channel) Unmute(dir string) error

Unmute stops muting of the channel in the given direction (one of "in", "out", or "both")

type ChannelCallerId

type ChannelCallerId struct {
	Event
	Caller_presentation     int     `json:"caller_presentation"`     // The numeric portion
	Caller_presentation_txt string  `json:"caller_presentation_txt"` // The textual portion
	Channel                 Channel `json:"channel"`
}

ChannelCallerId events indicate a channel's caller Id information has changed

type ChannelConnectedLine

type ChannelConnectedLine struct {
	Event
	Channel Channel `json:"channel"`
}

ChannelConnectedLine events indicate a channel has changed its connected line

type ChannelCreated

type ChannelCreated struct {
	Event
	Channel Channel `json:"channel"`
}

ChannelCreated events indicate a channel has been created

type ChannelDestroyed

type ChannelDestroyed struct {
	Event
	Cause     int     `json:"cause"`
	Cause_txt string  `json:"cause_txt"`
	Channel   Channel `json:"channel"`
}

ChannelDestroyed events indicate a channel has been destroyed

type ChannelDialplan

type ChannelDialplan struct {
	Event
	Channel           Channel `json:"channel"`
	Dialplan_app      string  `json:"dialplan_app"`      // The application which is to be executed
	Dialplan_app_data string  `json:"dialplan_app_data"` // The data to be passed to the application
}

ChannelDialplan events indicate a channel has changed its location in the dialplan

NOTE: This event also most likely implies the channel is leaving the control of this
ARI application

type ChannelDtmfReceived

type ChannelDtmfReceived struct {
	Event
	Channel     Channel `json:"channel"`
	Digit       string  `json:"digit"`       // The DTMF digit which was received (0-9A-E*#)
	Duration_ms int     `json:"duration_ms"` // The duration of the DTMF tone, in milliseconds
}

ChannelDtmfReceived events indicate a channel has received a DTMF tone.

NOTE: this event is sent at the _end_ of the DTMF tone (and there is no indication
for the _start_ of the DTMF tone)

type ChannelEnteredBridge

type ChannelEnteredBridge struct {
	Event
	Bridge  Bridge  `json:"bridge"`
	Channel Channel `json:"channel"`
}

ChannelEngteredBridge events indicate that a channel has joined a bridge

type ChannelEvent

type ChannelEvent struct {
	Event
	Channel Channel `json:"channel,omitempty"` // Affected channel
}

ChannelEvent (meta) is an event which affects a channel

type ChannelHangupRequest

type ChannelHangupRequest struct {
	Event
	Cause   int     `json:"cause,omitempty"` // Integer cause code
	Channel Channel `json:"channel"`
	Soft    bool    `json:"soft,omitempty"` // Whether the request was "soft"
}

ChannelHangupRequest events indicate that a channel has received a hangup request

TODO: find out if the application is supposed to act on this, or whether
this event is purely advisory

type ChannelHold

type ChannelHold struct {
	Event
	Channel    Channel `json:"channel"`
	MusicClass string  `json:"musicclass"` // The music class being played to the held channel
}

ChannelHold events indicate that a channel has been put on hold

type ChannelLeftBridge

type ChannelLeftBridge struct {
	Event
	Bridge  Bridge  `json:"bridge"`
	Channel Channel `json:"channel"`
}

ChannelLeftBridge events indicate that a channel has left a bridge

type ChannelStateChange

type ChannelStateChange struct {
	Event
	Channel Channel `json:"channel"`
}

ChannelStateChange events indicate that the state of a channel has changed

TODO: enumerate the possible channel states

type ChannelTalkingFinished

type ChannelTalkingFinished struct {
	Event
	Channel  Channel `json:"channel"`
	Duration int     `json:"duration"` // Duration (in milliseconds) of the talking
}

ChannelTalkingFinished events indicate that previously-detected talking on a channel is now absent

type ChannelTalkingStarted

type ChannelTalkingStarted struct {
	Event
	Channel Channel `json:"channel"`
}

ChannelTalkingStarted events indicate that talking has been detected on a channel

type ChannelUnhold

type ChannelUnhold struct {
	Event
	Channel Channel `json:"channel"`
}

ChannelUnhold events indicate that a channel has removed from Hold

type ChannelUserevent

type ChannelUserevent struct {
	Event
	Bridge    Bridge      `json:"bridge,omitempty"`
	Channel   Channel     `json:"channel,omitempty"`
	Endpoint  Endpoint    `json:"endpoint,omitempty"`
	Eventname string      `json:"eventname"` // Name of the user event
	Userevent interface{} `json:"userevent"` // Custome data sent with the user event
}

ChannelUserevent events are custom-formatted events which have been received

TODO: figure out if these include AMI user events, etc, and how the data is
formatted

type ChannelVarset

type ChannelVarset struct {
	Event
	Channel  Channel `json:"channel,omitempty"` // If not present, variable is global
	Value    string  `json:"value"`             // New value
	Variable string  `json:"variable"`          // Variable name
}

ChannelVarset events indicate a channel variable has been set (or changed)

type Client

type Client struct {
	Options *Options // client options

	WSConfig *websocket.Config // websocket connection configuration

	ReadyChan chan struct{}

	Bus *Bus // event bus

	TestMode bool // Client is in test mode: no actual HTTP requests will be made
	// contains filtered or unexported fields
}

Client describes an ARI connection to an Asterisk server Create one client for each ARI application

func ClientFromContext

func ClientFromContext(ctx context.Context) (*Client, bool)

ClientFromContext returns the Client stored in the context with the default key

func ClientFromContextWithKey

func ClientFromContextWithKey(ctx context.Context, name string) (*Client, bool)

ClientFromContextWithKey returns the Client stored in the context with the given keyname

func NewClient

func NewClient(opts *Options) *Client

NewClient creates a new Asterisk client This function does not attempt to connect to Asterisk itself. The ARI URL and websocket URL may also be defined by environment variables ARI_URL and ARI_WSURL, respectively; explicitly-supplied values for these in the supplied `Options` struct will override any environment variables. Defaults for each are to connect to `localhost` at the normal locations for each.

Additionally, username and password for the ARI connection may also be supplied by environment variables ARI_USERNAME and ARI_PASSWORD, respectively. There are no defaults for these values.

func (*Client) AddChannel

func (c *Client) AddChannel(id string, req AddChannelRequest) error

AddChannel adds a channel to a bridge Equivalent to Post /bridges/{id}/addChannel

func (*Client) AnswerChannel

func (c *Client) AnswerChannel(channelId string) error

Answer a channel Equivalent to Post /channels/{channelId}/answer

func (*Client) BridgeDelete

func (c *Client) BridgeDelete(id string) error

BridgeDelete shuts down a bridge. If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand. This means that the channels themselves are not deleted. Equivalent to DELETE /bridges/{id}

func (*Client) BridgeStopMoh

func (c *Client) BridgeStopMoh(id string) error

BridgeStopMoh stops playing music on hold to a bridge. This will only stop music on hold being played via POST bridges/{id}/moh. Equivalent to DELETE /bridges/{id}/moh

func (*Client) ChangeDeviceState

func (c *Client) ChangeDeviceState(deviceName string, deviceState string) error

Change the state of a device controlled by ARI. (Note - implicitly creates the device state). Equivalent to PUT /deviceStates/{deviceName}

func (*Client) ChangeMailboxState

func (c *Client) ChangeMailboxState(mailboxName string, oldMessages int, newMessages int) error

Change the state of a mailbox. (Note - implicitly creates the mailbox). Equivalent to PUT /mailboxes/{mailboxName}

func (*Client) CheckDirection

func (c *Client) CheckDirection(dir *string) error

func (*Client) Close

func (c *Client) Close()

Close closes the ARI client

func (*Client) ContinueChannel

func (c *Client) ContinueChannel(channelId string, req ContinueChannelRequest) error

Exit application and continue execution in the dialplan Equivalent to Post /channels/{channelId}/continue

func (*Client) ControlPlayback

func (c *Client) ControlPlayback(playbackID string, operation string) error

ControlPlayback allows the user to manipulate an in-process playback. TODO: list available operations. (Equivalent to POST /playbacks/{playbackID}/control)

func (*Client) CopyStoredRecording

func (c *Client) CopyStoredRecording(recordingName string, destination string) (StoredRecording, error)

CopyStoredRecording copies a stored recording to a new destination within the stored recordings tree. Equivalent to Post /recordings/stored/{recordingName}/copy

func (*Client) CreateBridge

func (c *Client) CreateBridge(req CreateBridgeRequest) (Bridge, error)

CreateBridge creates a new bridge Equivalent to POST /bridges

func (*Client) CreateChannel

func (c *Client) CreateChannel(req OriginateRequest) (Channel, error)

CreateChannel originates a new call

func (*Client) CreateChannelWithId

func (c *Client) CreateChannelWithId(id string, req OriginateRequest) (Channel, error)

CreateChannelWithId originates a new call with the given channel Id

func (*Client) CreateUserEvent

func (c *Client) CreateUserEvent(eventName string, req CreateUserEventRequest) error

Generate a new user event Equivalent to Post /events/user/{eventName}

func (*Client) Delete

func (c *Client) Delete(url string, ret interface{}, req string) error

Delete calls the ARI server with a DELETE request

func (*Client) DeleteDeviceState

func (c *Client) DeleteDeviceState(deviceName string) error

Destroy a device-state controlled by ARI. Equivalent to DELETE /deviceStates/{deviceName}

func (*Client) DeleteMailbox

func (c *Client) DeleteMailbox(mailboxName string) error

Destroy a mailbox. Equivalent to DELETE /mailboxes/{mailboxName}

func (*Client) DeleteStoredRecording

func (c *Client) DeleteStoredRecording(recordingName string) error

DeleteStoredRecording deletes a stored recording Equivalent to DELETE /recordings/stored/{recordingName}

func (*Client) Get

func (c *Client) Get(url string, ret interface{}) error

Get calls the ARI server with a GET request

func (*Client) GetApplication

func (c *Client) GetApplication(applicationName string) (Application, error)

GetApplication returns the details of a given ARI application Equivalent to GET /applications/{applicationName}

func (*Client) GetAsteriskInfo

func (c *Client) GetAsteriskInfo(only string) (*AsteriskInfo, error)

GetAsteriskInfo returns various data about the Asterisk system Equivalent to GET /asterisk/info

func (*Client) GetAsteriskVariable

func (c *Client) GetAsteriskVariable(variable string) (string, error)

GetAsteriskVariable returns the value of the given global variable Equivalent to GET /asterisk/variable

func (*Client) GetBridge

func (c *Client) GetBridge(id string) (Bridge, error)

GetBridge returns the details of a bridge Equivalent to Get /bridges/{bridgeId}

func (*Client) GetChannel

func (c *Client) GetChannel(channelId string) (Channel, error)

Get a specific channel's details Equivalent to Get /channels/{channelId}

func (*Client) GetChannelVariable

func (c *Client) GetChannelVariable(channelId string, variable string) (Variable, error)

Get the value of a channel variable or function Equivalent to Get /channels/{channelId}/variable

func (*Client) GetDeviceState

func (c *Client) GetDeviceState(deviceName string) (DeviceState, error)

Retrieve the current state of a specified device Equivalent to GET /deviceStates/{deviceName}

func (*Client) GetEndpoint

func (c *Client) GetEndpoint(tech string, resource string) (Endpoint, error)

GetEndpoint requests the details of an endpoint from Asterisk

func (*Client) GetEndpointsByTech

func (c *Client) GetEndpointsByTech(tech string) ([]Endpoint, error)

List available endpoints for a given endpoint technology Equivalent to Get /endpoints/{tech}

func (*Client) GetEvents

func (c *Client) GetEvents(app string) (Message, error)

Websocket connection for events Equivalent to GET /events

func (*Client) GetLiveRecording

func (c *Client) GetLiveRecording(recordingName string) (*LiveRecording, error)

GetLiveRecording returns a specific live recording Equivalent to GET /recordings/live/{recordingName}

func (*Client) GetMailbox

func (c *Client) GetMailbox(mailboxName string) (Mailbox, error)

Retrieve the current state of a specific mailbox Equivalent to GET /mailboxes/{mailboxName}

func (*Client) GetPlaybackDetails

func (c *Client) GetPlaybackDetails(playbackID string) (Playback, error)

GetPlaybackDetails returns a playback's details. (Equivalent to GET /playbacks/{playbackID})

func (*Client) GetSound

func (c *Client) GetSound(soundId string) (Sound, error)

Get a sound's details Equivalent to GET /sounds/{soundId}

func (*Client) GetStoredRecording

func (c *Client) GetStoredRecording(recordingName string) (StoredRecording, error)

GetStoredRecording returns a stored recording's details Equivalent to GET /recordings/stored/{recordingName}

func (*Client) HangupChannel

func (c *Client) HangupChannel(channelId string, reason string) error

Delete (i.e. hangup) a channel. Equivalent to DELETE /channels/{channelId}

func (*Client) HoldChannel

func (c *Client) HoldChannel(channelId string) error

Hold a channel Equivalent to Post /channels/{channelId}/hold

func (*Client) ListApplications

func (c *Client) ListApplications() ([]Application, error)

ListApplications returns the list of ARI applications on the Asterisk server Equivalent to GET /applications

func (*Client) ListBridges

func (c *Client) ListBridges() ([]Bridge, error)

ListBridges returns all active bridges in Asterisk Equivalent to GET /bridges

func (*Client) ListChannels

func (c *Client) ListChannels() ([]Channel, error)

List all active channels in asterisk Equivalent to Get /channels

func (*Client) ListDeviceStates

func (c *Client) ListDeviceStates() ([]DeviceState, error)

ListDeviceStates returns the list of all ARI controlled device states Equivalent to GET /deviceStates

func (*Client) ListEndpoints

func (c *Client) ListEndpoints() ([]Endpoint, error)

ListEndpoints lists all endpoints TODO: associated with the application, or on the entire system?

func (*Client) ListMailboxes

func (c *Client) ListMailboxes() ([]Mailbox, error)

List all mailboxes on asterisk server Equivalent to GET /mailboxes

func (*Client) ListSounds

func (c *Client) ListSounds(filters map[string]string) ([]Sound, error)

ListSounds returns a list of (all) the available sounds

func (*Client) ListSoundsFiltered

func (c *Client) ListSoundsFiltered(filters map[string]string) ([]Sound, error)

ListSoundsFiltered lists sounds limited by the provided filters valid filters are "lang" and "format"

func (*Client) ListStoredRecordings

func (c *Client) ListStoredRecordings() ([]StoredRecording, error)

ListStoredRecordings lists all completed recordings Equivalent to GET /recordings/stored

func (*Client) Listen

func (c *Client) Listen(ctx context.Context) (err error)

Listen maintains and listens to a websocket connection until told to stop.

func (*Client) MuteChannel

func (c *Client) MuteChannel(channelId string, direction string) error

Mute a channel Equivalent to Post /channels/{channelId}/mute Viable options are "in," "out," or "both"

func (*Client) MuteLiveRecording

func (c *Client) MuteLiveRecording(recordingName string) error

MuteLiveRecording mutes a live recording Equivalent to Post /recordings/live/{recordingName}/mute

func (*Client) NewBridge

func (c *Client) NewBridge() (Bridge, error)

NewBridge is a simple wrapper to create a new, unique bridge, with the default options

func (*Client) NewBridgeWithID

func (c *Client) NewBridgeWithID(id string) (Bridge, error)

NewBridgeWithID is a simple wrapper to create a new, unique bridge, with the default options

func (*Client) NewChannel

func (c *Client) NewChannel(endpoint string, cid *CallerId, vars map[string]string) (Channel, error)

NewChannel is a shorthand for creating a new channel. It generates a unique Id, sets the destination to be the current application, and passes any variables through; pass nil for vars if no variables are needed

func (*Client) NewLocalChannel

func (c *Client) NewLocalChannel(endpoint string, cid *CallerId, vars map[string]string) (Channel, Channel, error)

NewLocalChannel creates a new local channel and returns each side

func (*Client) NewOriginateRequest

func (c *Client) NewOriginateRequest(endpoint string) OriginateRequest

NewOriginateRequest generates an originate request with a unique channel Id, destination equal to the current client, and an unlimited call timeout

func (*Client) PauseLiveRecording

func (c *Client) PauseLiveRecording(recordingName string) error

PauseLiveRecording pauses a live recording Equivalent to Post /recordings/live/{recordingName}/pause

func (*Client) PlayMOHToChannel

func (c *Client) PlayMOHToChannel(channelId string, mohClass string) error

Play music on hold to a channel Equivalent to Post /channels/{channelId}/moh

func (*Client) PlayMedia

func (c *Client) PlayMedia(channelId, mediaUri string) (string, error)

PlayMedia is a wrapper to initiate a playback with the given Media URI, returning the playback id

func (*Client) PlayMusicOnHold

func (c *Client) PlayMusicOnHold(id string, class string) error

PlayMusicOnHold plays a music on hold class to a bridge or changes the existing MOH class Equivalent to Post /bridges/{bridgeId}/moh (music on hold)

func (*Client) PlaySilenceToChannel

func (c *Client) PlaySilenceToChannel(channelId string) error

Play silence to a channel Equivalent to Post /channels/{channelId}/silence

func (*Client) PlayToBridge

func (c *Client) PlayToBridge(id string, req PlayMediaRequest) (Playback, error)

PlayToBridge starts playback of media on specified bridge Equivalent to Post /bridges/{id}/play

func (*Client) PlayToBridgeByID

func (c *Client) PlayToBridgeByID(id string, playbackID string, req PlayMediaRequest) (Playback, error)

PlayToBridgeByID starts playback of specific media on specified bridge Equivalent to Post /bridges/{id}/play/{playbackID}

func (*Client) PlayToChannel

func (c *Client) PlayToChannel(channelId string, req PlayMediaRequest) (Playback, error)

Start playback of media to a channel Equivalent to Post /channels/{channelId}/play

func (*Client) PlayToChannelById

func (c *Client) PlayToChannelById(channelId string, playbackId string, req PlayMediaRequest) (Playback, error)

Specifiy media to playback to a channel Equivalent to Post /channels/{channelId}/play/{playbackId}

func (*Client) Post

func (c *Client) Post(requestURL string, ret interface{}, req interface{}) error

Post calls the ARI server with a POST request.

func (*Client) Put

func (c *Client) Put(url string, ret interface{}, req interface{}) error

Put calls the ARI server with a PUT request.

func (*Client) RecordBridge

func (c *Client) RecordBridge(id string, req *RecordRequest) (*LiveRecording, error)

RecordBridge starts a recording on specified bridge Equivalent to Post /bridges/{id}/record

func (*Client) RecordChannel

func (c *Client) RecordChannel(channelId string, req *RecordRequest) (*LiveRecording, error)

Start a live recording Equivalent to Post /channels/{channelId}/record

func (*Client) ReloadModule

func (c *Client) ReloadModule(name string) error

ReloadModule tells asterisk to load the given module

func (*Client) RemoveChannel

func (c *Client) RemoveChannel(id string, channelID string) error

RemoveChannel removes the specified channel from a bridge Equivalent to Post /bridges/{id}/removeChannel

func (*Client) ResumeLiveRecording

func (c *Client) ResumeLiveRecording(recordingName string) error

ResumeLiveRecording resumes (unpauses) a live recording Equivalent to DELETE /recordings/live/{recordingName}/pause

func (*Client) RingChannel

func (c *Client) RingChannel(channelId string) error

Indicate ringing to a channel Equivalent to Post /channels/{channelId}/ring

func (*Client) ScrapLiveRecording

func (c *Client) ScrapLiveRecording(recordingName string) error

ScrapLiveRecording stops a live recording and discard it Equivalent to DELETE /recordings/live/{recordingName} TODO reproduce this error in isolation: does not delete. Cannot delete any recording produced by this.

func (*Client) SendDTMFToChannel

func (c *Client) SendDTMFToChannel(channelId string, req SendDTMFToChannelRequest) error

Send provided DTMF to a given channel Equivalent to Post /channels/{channelId}/dtmf

func (*Client) SendMessage

func (c *Client) SendMessage(from, tech, resource, body string, vars map[string]string) error

SendMessage sends a text message to an endpoint

func (*Client) SendMessageByUri

func (c *Client) SendMessageByUri(from, to, body string, vars map[string]string) error

SendMessageByUri sends a text message to an endpoint by free-form URI (rather than tech/resource)

func (*Client) SetAsteriskVariable

func (c *Client) SetAsteriskVariable(variable string, value string) error

SetAsteriskVariable sets a global channel variable (Equivalent to POST /asterisk/variable)

func (*Client) SetChannelVariable

func (c *Client) SetChannelVariable(channelId string, variable string, value string) error

Set the value of a variable Equivalent to Post /channels/{channelId}/variable

func (*Client) StartSnoopChannel

func (c *Client) StartSnoopChannel(channelId string, req SnoopRequest) (Channel, error)

Start snooping Equivalent to Post /channels/{channelId}/snoop

func (*Client) StartSnoopChannelById

func (c *Client) StartSnoopChannelById(channelId string, snoopId string, req SnoopRequest) (Channel, error)

Start Snooping by specific ID Equivalent to Post /channels/{channelId}/snoop/{snoopId}

func (*Client) StopHoldChannel

func (c *Client) StopHoldChannel(channelId string) error

Remove a channel from hold Equivalent to DELETE /channels/{channelId}/hold

func (*Client) StopLiveRecording

func (c *Client) StopLiveRecording(recordingName string) error

StopLiveRecording stops and stores a live recording Equivalent to Post /recordings/live/{recordingName}/stop

func (*Client) StopMohChannel

func (c *Client) StopMohChannel(channelId string) error

Stop playing music on hold to a channel Equivalent to DELETE /channels/{channelId}/moh

func (*Client) StopPlayback

func (c *Client) StopPlayback(playbackID string) error

StopPlayback stops a playback session. (Equivalent to DELETE /playbacks/{playbackID})

func (*Client) StopRinging

func (c *Client) StopRinging(channelId string) error

Stop ringing indication on a channel if locally generated. Equivalent to DELETE /channels/{channelId}/ring

func (*Client) StopSilenceChannel

func (c *Client) StopSilenceChannel(channelId string) error

Stop playing silence to a channel Equivalent to DELETE /channels/{channelId}/silence

func (*Client) SubscribeApplication

func (c *Client) SubscribeApplication(applicationName string, eventSource string) (Application, error)

SubscribeApplication subscribes the given application to an event source event source may be one of:

  • channel:<channelId>
  • bridge:<bridgeId>
  • endpoint:<tech>/<resource> (e.g. SIP/102)
  • deviceState:<deviceName>

Equivalent to POST /applications/{applicationName}/subscription

func (*Client) UnMuteChannel

func (c *Client) UnMuteChannel(channelId string, direction string) error

Unmute a channel Equivalent to DELETE /channels/{channelId}/mute

func (*Client) UnmuteLiveRecording

func (c *Client) UnmuteLiveRecording(recordingName string) error

UnmuteLiveRecording unmutes a live recording Equivalent to DELETE /recordings/live/{recordingName}/mute

func (*Client) UnsubscribeApplication

func (c *Client) UnsubscribeApplication(applicationName string, eventSource string) (Application, error)

UnsubscribeApplication unsubscribes (removes a subscription to) a given ARI application from the provided event source Equivalent to DELETE /applications/{applicationName}/subscription

func (*Client) UpsertBridge

func (c *Client) UpsertBridge(id string, req CreateBridgeRequest) (Bridge, error)

UpsertBridge adds or updates a bridge Equivalent to POST /bridges/{bridgeId}

type ConfigInfo

type ConfigInfo struct {
	DefaultLanguage string  `json:"default_language"`
	MaxChannels     int     `json:"max_channels,omitempty"` //omitempty denotes an optional field, meaning the field may not be present if no value is assigned.
	MaxLoad         float64 `json:"max_load,omitempty"`
	MaxOpenFiles    int     `json:"max_open_files,omitempty"`
	Name            string  `json:"name"`  // Asterisk system name
	SetID           SetID   `json:"setid"` // Effective user/group id under which Asterisk is running
}

ConfigInfo describes information about the Asterisk configuration

type ContactInfo

type ContactInfo struct {
	AOR       string `json:"aor"`                      // Address of Record for this contact
	Status    string `json:"contact_status"`           // Current status of the contact
	Roundtrip string `json:"roundtrip_usec,omitempty"` // Current round trip time, in microseconds
	URI       string `json:"uri"`                      // The location URI of the contact
}

ContactInfo describes a Contact

func (*ContactInfo) Latency

func (c *ContactInfo) Latency() time.Duration

Latency returns the round-trip time for this contact

type ContactStatusChanged

type ContactStatusChanged struct {
	Event
	Endpoint    Endpoint    `json:"endpoint"`
	ContactInfo ContactInfo `json:"contact_info"`
}

ContactStatusChanged events indicate that a contact state has changed

type ContinueChannelRequest

type ContinueChannelRequest struct {
	Context   string `json:"context,omitempty"`
	Extension string `json:"extension,omitempty"`
	Priority  int64  `json:"priority,omitempty"`
}

priority is of type long = int64 Request structure for ContinueChannel. All fields are optional. The three fields mirror the construction of a channel by Dialplan, as the function returns a channel to the dialplan.

type CreateBridgeRequest

type CreateBridgeRequest struct {
	ID   string `json:"bridgeId,omitempty"`
	Type string `json:"type,omitempty"`
	Name string `json:"name,omitempty"`
}

CreateBridgeRequest is the structure for creating a bridge. No properies are required, meaning an empty struct may be passed to 'CreateBridge'

type CreateUserEventRequest

type CreateUserEventRequest struct {
	Application string `json:"application"`
	Source      string `json:"source,omitempty"`
	Variables   string `json:"variables,omitempty"`
}

Request structure for creating a user event. Only Application is required.

type DeviceState

type DeviceState struct {
	Name  string `json:"name"`
	State string `json:"state"`
}

DeviceState describes the state of a device

type DeviceStateChanged

type DeviceStateChanged struct {
	Event
	Device_state DeviceState `json:"device_state"`
}

DeviceStateChanged events indicate that a device state has changed

type Dial

type Dial struct {
	Event
	Caller     Channel `json:"caller,omitempty"`     // Dialing channel (if not system-originated)
	Dialstatus string  `json:"dialstatus"`           // Present status of the dial attempt
	Dialstring string  `json:"dialstring,omitempty"` // The string describing the dial
	Forward    string  `json:"forward,omitempty"`    // If present, indicates the forwarding target TODO: what is the format of this?
	Forwarded  Channel `json:"forwarded,omitempty"`  // If present, channel of forwarding target
	Peer       Channel `json:"peer"`                 // Dialed channel
}

Dial events indicate the dialing state for a channel has changed

type DialplanCEP

type DialplanCEP struct {
	Context  string `json:"context"`
	Exten    string `json:"exten"`
	Priority int64  `json:"priority"` //int64 derived from Java's 'long'
}

DialplanCEP describes a location in the dialplan (context,extension,priority)

type Endpoint

type Endpoint struct {
	ChannelIds []string `json:"channel_ids"`     // List of channel Ids which are associated with this endpoint
	Resource   string   `json:"resource"`        // The endpoint's resource name
	State      string   `json:"state,omitempty"` // The state of the endpoint
	Technology string   `json:"technology"`      // The technology of the endpoint (e.g. SIP, PJSIP, DAHDI, etc)
}

Endpoint describes an external device which may offer or accept calls to or from Asterisk. Devices are defined by a technology/resource pair.

Allowed states: 'unknown', 'offline', 'online'

type EndpointStateChange

type EndpointStateChange struct {
	Event
	Endpoint Endpoint `json:"endpoint"`
}

EndpointStateChange events indicate that an endpoint has changed state

type Event

type Event struct {
	Message
	Application string       `json:"application"`
	Timestamp   AsteriskDate `json:"timestamp,omitempty"`
}

Event is the base struct for all events

func NewEvent

func NewEvent(raw []byte) (*Event, error)

NewEvent constructs an Event from a byte slice (unmarshals the event from Ari)

func (*Event) GetApplication

func (e *Event) GetApplication() string

func (*Event) GetType

func (e *Event) GetType() string

type Eventer

type Eventer interface {
	MessageRawer
	GetApplication() string
	GetType() string
}

type FormatLangPair

type FormatLangPair struct {
	Format   string `json:"format"`
	Language string `json:"language"`
}

FormatLangPair describes the format and language of a sound file

type LiveRecording

type LiveRecording struct {
	Cause       string `json:"cause,omitempty"`            // If failed, the cause of the failure
	DurationSec int    `json:"duration,omitempty"`         // Length of recording in seconds
	Format      string `json:"format"`                     // Format of recording (wav, gsm, etc)
	Name        string `json:"name"`                       // (base) name for the recording
	SilenceSec  int    `json:"silence_duration,omitempty"` // If silence was detected in the recording, the duration in seconds of that silence (requires that maxSilenceSeconds be non-zero)
	State       string `json:"state"`                      // Current state of the recording
	TalkingSec  int    `json:"talking_duration,omitempty"` // Duration of talking, in seconds, that has been detected in the recording (requires that maxSilenceSeconds be non-zero)
	TargetURI   string `json:"target_uri"`                 // URI for the channel or bridge which is being recorded (TODO: figure out format for this)
	// contains filtered or unexported fields
}

LiveRecording describes a recording which is in progress

func Record

func Record(ctx context.Context, r Recorder, name string, opts *RecordingOptions) (*LiveRecording, error)

Record starts a recording on the given Recorder.

func (*LiveRecording) Delete

func (l *LiveRecording) Delete() error

Delete current LiveRecording

func (*LiveRecording) Duration

func (l *LiveRecording) Duration() (dur time.Duration)

Duration returns the duration of the live recording, if known

func (*LiveRecording) Mute

func (l *LiveRecording) Mute() error

Mute current LiveRecording

func (*LiveRecording) Pause

func (l *LiveRecording) Pause() error

Pause current LiveRecording

func (*LiveRecording) Resume

func (l *LiveRecording) Resume() error

Resume unpauses the current LiveRecording

func (*LiveRecording) Scrap

func (l *LiveRecording) Scrap() error

Scrap Stops and deletes the current LiveRecording TODO: reproduce this error in isolation: does not delete. Cannot delete any recording produced by this.

func (*LiveRecording) SilenceDuration

func (l *LiveRecording) SilenceDuration() (dur time.Duration)

SilenceDuration returns the duration of the detected silence during the recording, if known

func (*LiveRecording) Status

func (l *LiveRecording) Status() int

Status returns the status of the recording.

func (*LiveRecording) Stop

func (l *LiveRecording) Stop() error

Stop and store current LiveRecording

func (*LiveRecording) TalkingDuration

func (l *LiveRecording) TalkingDuration() (dur time.Duration)

TalkingDuration returns the duration of the detected talking during the recording, if known

func (*LiveRecording) Unmute

func (l *LiveRecording) Unmute() error

Unmute current LiveRecording

type Mailbox

type Mailbox struct {
	Name         string `json:"name"`
	New_messages int    `json:"new_messages"` // Number of new (unread) messages
	Old_messages int    `json:"old_messages"` // Number of old (read) messages
}

Mailbox respresents the state of an Asterisk (voice) mailbox

type Message

type Message struct {
	RawMessage
	Type string `json:"type"`
}

Message is the first extension of the RawMessage type, containing only a Type

func NewMessage

func NewMessage(raw []byte) (*Message, error)

Construct a Message from a byte slice

type MessageRawer

type MessageRawer interface {
	SetRaw(*[]byte)
	GetRaw() *[]byte
}

type MissingParams

type MissingParams struct {
	Message
	Params []string `json:"params"` // List of missing parameters which are required
}

MissingParams is an error message response emitted when a request does not contain required parameters

type Options

type Options struct {
	// Application is the the name of this ARI application
	Application string

	// URL is the root URL of the ARI server (asterisk box).
	// Default to http://localhost:8088/ari
	URL string

	// WebsocketURL is the URL for ARI Websocket events.
	// Defaults to the events directory of URL, with a protocol of ws.
	// Usually ws://localhost:8088/ari/events.
	WebsocketURL string

	// Username for ARI authentication
	Username string

	// Password for ARI authentication
	Password string
}

Options describes client connection options

type OriginateRequest

type OriginateRequest struct {
	Endpoint string `json:"endpoint"`           // Endpoint to use (tech/resource notation)
	Timeout  int    `json:"timeout,omitempty"`  // Dial Timeout in seconds (-1 = no limit)
	CallerId string `json:"callerId,omitempty"` // CallerId to set for outgoing call

	// One set of:
	Context   string `json:"context,omitempty"` // Drop the channel into the dialplan
	Extension string `json:"extension,omitempty"`
	Priority  int64  `json:"priority,omitempty"`
	// OR
	App     string `json:"app,omitempty"`     // Associate channel to Stasis (Ari) application
	AppArgs string `json:"appArgs,omitempty"` // Arguments to the application

	// Channel Id declarations
	ChannelId      string `json:"channelId,omitempty"`      // Optionally assign channel id
	OtherChannelId string `json:"otherChannelId,omitempty"` // Optionally assign second channel's id (only for local channels)

	Variables map[string]string `json:"variables,omitempty"` // Channel variables to set
}

OriginateRequest is the basic structure for all channel creation methods

type Peer

type Peer struct {
	Address string       `json:"address,omitempty"` // IP Address of the peer
	Cause   string       `json:"cause,omitempty"`   // Reason associated with change in peer_status
	Status  string       `json:"peer_status"`       // The current state of the peer
	Port    string       `json:"port,omitempty"`    // The port of the peer
	Time    AsteriskDate `json:"time,omitempty"`    // The last known time the peer was contacted
}

Peer describes a remote peer that communicates with Asterisk

type PeerStatusChange

type PeerStatusChange struct {
	Event
	Endpoint Endpoint `json:"endpoint"`
	Peer     Peer     `json:"peer"`
}

PeerStatusChange events indicate that a peer has changed state

type PlayMediaRequest

type PlayMediaRequest struct {
	Media    string `json:"media"`
	Lang     string `json:"lang,omitempty"`
	Offsetms int    `json:"offsetms,omitempty"`
	Skipms   int    `json:"skipms,omitempty"`

	//PlaybackId unnecessary if specifically naming it in query path
	PlaybackId string `json:"playbackId,omitempty"`
}

type Playback

type Playback struct {
	ID        string `json:"id"` // Unique ID for this playback session
	Language  string `json:"language,omitempty"`
	MediaURI  string `json:"media_uri"`  // URI for the media which is to be played
	State     string `json:"state"`      // State of the playback operation
	TargetURI string `json:"target_uri"` // URI of the channel or bridge on which the media should be played (follows format of 'type':'name')
	// contains filtered or unexported fields
}

Playback describes an ARI playback handle

func (*Playback) Control

func (p *Playback) Control(operation string) error

Control the current Playback

func (*Playback) Stop

func (p *Playback) Stop() error

Stop the current Playback.

type PlaybackFinished

type PlaybackFinished struct {
	Event
	Playback Playback `json:"playback"`
}

PlaybackFinished events indicate that a media playback operation has completed

type PlaybackOptions

type PlaybackOptions struct {
	// ID is an optional ID to use for the playback's ID. If one
	// is not supplied, an ID will be randomly generated internally.
	// NOTE that this ID will only be used for the FIRST playback
	// in a queue.  All subsequent playback IDs will be randomly generated.
	ID string

	// DTMF is an optional channel for received DTMF tones received during the playback.
	// This channel will NOT be closed by the playback.
	DTMF chan<- *ChannelDtmfReceived

	// ExitOnDTMF defines a list of DTMF digits on receipt of which will
	// terminate the playback of the queue.  You may set this to AllDTMF
	// in order to match any DTMF digit.
	ExitOnDTMF string

	// Done is an optional channel for receiving notification when the playback
	// is complete.  This is useful if the playback is to be executed asynchronously.
	// This channel will be closed by the playback when playback the is complete.
	Done chan<- struct{}
}

PlaybackOptions describes various options which are available to playback operations.

type PlaybackQueue

type PlaybackQueue struct {
	// contains filtered or unexported fields
}

PlaybackQueue represents a sequence of audio playbacks which are to be played on the associated Player

func NewPlaybackQueue

func NewPlaybackQueue() *PlaybackQueue

NewPlaybackQueue creates (but does not start) a new playback queue.

func (*PlaybackQueue) Add

func (pq *PlaybackQueue) Add(mediaURIs ...string)

Add appends one or more mediaURIs to the playback queue

func (*PlaybackQueue) Flush

func (pq *PlaybackQueue) Flush()

Flush empties a playback queue. NOTE that this does NOT stop the current playback.

func (*PlaybackQueue) Play

func (pq *PlaybackQueue) Play(ctx context.Context, p Player, opts *PlaybackOptions) error

Play starts the playback of the queue to the Player.

func (*PlaybackQueue) PlayAsync

func (pq *PlaybackQueue) PlayAsync(ctx context.Context, p Player, opts *PlaybackOptions) chan error

PlayAsync plays the queue, returing immediately with an error channel, which will pass any errors and be closed on completion of the queue.

func (*PlaybackQueue) ReceivedDTMF

func (pq *PlaybackQueue) ReceivedDTMF() string

ReceivedDTMF returns any DTMF which has been received by the PlaybackQueue.

type PlaybackStarted

type PlaybackStarted struct {
	Event
	Playback Playback `json:"playback"`
}

PlaybackStarted events indicate that a media playback operation has begun

type Player

type Player interface {
	Play(string) (string, error)
	GetClient() *Client
}

A Player is anyhing which can "Play" an mediaURI

type PlayerRecorder

type PlayerRecorder interface {
	Record(string, *RecordingOptions) (*LiveRecording, error)
	Play(string) (string, error)
	GetClient() *Client
}

A PlayerRecorder is anywhich which can Record and Play

type RawMessage

type RawMessage struct {
	// contains filtered or unexported fields
}

func (*RawMessage) DecodeAs

func (m *RawMessage) DecodeAs(v MessageRawer) error

DecodeAs converts the current message to a new message type

func (*RawMessage) GetRaw

func (m *RawMessage) GetRaw() *[]byte

Get the __raw value of this RawMessage

func (*RawMessage) SetRaw

func (m *RawMessage) SetRaw(raw *[]byte)

Set the __raw value of this RawMessage

type RecordRequest

type RecordRequest struct {
	Name               string `json:"name"`
	Format             string `json:"format"`
	MaxDurationSeconds int    `json:"maxDurationSeconds,omitempty"`
	MaxSilenceSeconds  int    `json:"maxSilenceSeconds,omitempty"`
	IfExists           string `json:"ifExists,omitempty"`
	Beep               bool   `json:"beep,omitempty"`
	TerminateOn        string `json:"terminateOn,omitempty"`
}

type Recorder

type Recorder interface {
	Record(string, *RecordingOptions) (*LiveRecording, error)
	GetClient() *Client
}

A Recorder is anything which can "Record"

type RecordingFailed

type RecordingFailed struct {
	Event
	Recording LiveRecording `json:"recording"`
}

RecordingFailed events indicate that a recording operation request has failed to complete

type RecordingFinished

type RecordingFinished struct {
	Event
	Recording LiveRecording `json:"recording"`
}

RecordingFinished events indicate that a recording operation has completed

type RecordingOptions

type RecordingOptions struct {
	// Format is the file format/encoding to which the recording should be stored.
	// This will usually be one of: slin, ulaw, alaw, wav, gsm.
	// If not specified, this will default to slin.
	Format string

	// MaxDuration is the maximum duration of the recording, after which the recording will
	// automatically stop.  If not set, there is no maximum.
	MaxDuration time.Duration

	// MaxSilence is the maximum duration of detected to be found before terminating the recording.
	MaxSilence time.Duration

	// Exists determines what should happen if the given recording already exists.
	// Valid values are: "fail", "overwrite", or "append".
	// If not specified, it will default to "fail"
	Exists string

	// Beep indicates whether a beep should be played to the recorded
	// party at the beginning of the recording.
	Beep bool

	// Terminate indicates whether the recording should be terminated on
	// receipt of a DTMF digit.
	// valid options are: "none", "any", "*", and "#"
	// If not specified, it will default to "none" (never terminate on DTMF).
	Terminate string
}

RecordingOptions describes the set of options available when making a recording.

func (*RecordingOptions) ToRequest

func (o *RecordingOptions) ToRequest(name string) *RecordRequest

ToRequest converts a set of recording options to a record request.

type RecordingStarted

type RecordingStarted struct {
	Event
	Recording LiveRecording `json:"recording"`
}

RecordingStarted events indicate that a recording operation has begun

type RequestError

type RequestError interface {
	error
	Code() int
}

RequestError describes an error with an error Code.

type SendDTMFToChannelRequest

type SendDTMFToChannelRequest struct {
	Dtmf     string `json:"dtmf,omitempty"`
	Before   int    `json:"before,omitempty"`
	Between  int    `json:"between,omitempty"`
	Duration int    `json:"duration,omitempty"`
	After    int    `json:"after,omitempty"`
}

SendDTMPFToChannel Request structure. All fields are optional.

type SetID

type SetID struct {
	Group string `json:"group"` // group id (not name? why string?)
	User  string `json:"user"`  // user id (not name? why string?)
}

SetID describes a userid/groupid pair

type SnoopRequest

type SnoopRequest struct {
	Spy     string `json:"spy,omitempty"`     //Direction of audio to spy on, default is 'none'
	Whisper string `json:"whisper,omitempty"` //Direction of audio to whisper into, default is 'none'
	App     string `json:"app"`               //Application that the snooping channel is placed into
	AppArgs string `json:"appArgs,omitempty"` //The application arguments to pass to the Stasis application

	//Only necessary for 'StartSnoopChannel'
	SnoopId string `json:"snoopId,omitempty"` //Unique ID to assign to snooping channel
}

Structure for snooping a channel. Only App is required.

type Sound

type Sound struct {
	Formats []FormatLangPair `json:"formats"`
	Id      string           `json:"id"`
	Text    string           `json:"text,omitempty"`
}

Sound describes a media file which may be played back

type StasisEnd

type StasisEnd struct {
	Event
	Args    []string `json:"args"`
	Channel Channel  `json:"channel"`
}

StasisEnd events indicate that a channel has left the Stasis (Ari) application

type StasisStart

type StasisStart struct {
	Event
	Args           []string `json:"args"`
	Channel        Channel  `json:"channel"`
	ReplaceChannel Channel  `json:"replacechannel,omitempty"` // TODO: find out what this is
}

StasisStart events indicate a channel has entered the Stasis (Ari) application

func (*StasisStart) GetChannel

func (s *StasisStart) GetChannel(c *Client) Channel

GetChannel returns the channel for whom the StasisStart event occurred, optionally attaching a copy of the ARI client

type StatusInfo

type StatusInfo struct {
	LastReloadTime AsteriskDate `json:"last_reload_time"`
	StartupTime    AsteriskDate `json:"startup_time"`
}

StatusInfo describes the state of an Asterisk system

type StoredRecording

type StoredRecording struct {
	Format string `json:"format"`
	Name   string `json:"name"`
	// contains filtered or unexported fields
}

StoredRecording describes a past recording which may be played back (via GetStoredRecording)

func (*StoredRecording) Copy

func (s *StoredRecording) Copy(destination string) (StoredRecording, error)

Copy current StoredRecording to a new name (retaining the existing copy)

type Subscription

type Subscription struct {
	C chan Eventer // channel for sending events to the subscriber
	// contains filtered or unexported fields
}

A Subscription is a wrapped channel for receiving events from the ARI event bus.

func (*Subscription) Cancel

func (s *Subscription) Cancel()

Cancel cancels the subscription and removes it from the event bus.

func (*Subscription) Next

func (s *Subscription) Next(ctx context.Context) Eventer

Next blocks for the next event in the subscription, returning that event when it arrives or nil if the subscription is canceled. Normally, one would listen to subscription.C directly, but this is a convenience function for providing a context to alternately cancel.

type SystemInfo

type SystemInfo struct {
	EntityID string `json:"entity_id"`
	Version  string `json:"version"`
}

SystemInfo describes information about the Asterisk system

type TextMessage

type TextMessage struct {
	Body      string                `json:"body"` // The body (text) of the message
	From      string                `json:"from"` // Technology-specific source URI
	To        string                `json:"to"`   // Technology-specific destination URI
	Variables []TextMessageVariable `json:"variables,omitempty"`
}

TextMessage describes text message

type TextMessageReceived

type TextMessageReceived struct {
	Event
	Endpoint Endpoint    `json:"endpoint,omitempty"`
	Message  TextMessage `json:"message"`
}

TextMessageReceived events indicate that an endpoint has emitted a text message

type TextMessageVariable

type TextMessageVariable struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

TextMessageVariable describes a key-value pair (associated with a text message)

type Variable

type Variable struct {
	Value string `json:"value"`
}

Variable describes the value of a channel variable

NOTE: the variable name is not included, so it must be
tracked with the request

Jump to

Keyboard shortcuts

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