import "github.com/staskobzar/goagi"
- Variables
- type AGI
- func New(r Reader, w Writer, dbg Debugger) (*AGI, error)
- func (agi *AGI) Answer() (Response, error)
- func (agi *AGI) AsyncAGIBreak() (Response, error)
- func (agi *AGI) ChannelStatus(channel string) (Response, error)
- func (agi *AGI) Command(cmd string) (Response, error)
- func (agi *AGI) ControlStreamFile(filename, digits string, args ...string) (Response, error)
- func (agi *AGI) DatabaseDel(family, key string) (Response, error)
- func (agi *AGI) DatabaseDelTree(family, keytree string) (Response, error)
- func (agi *AGI) DatabaseGet(family, key string) (Response, error)
- func (agi *AGI) DatabasePut(family, key, val string) (Response, error)
- func (agi *AGI) Env(key string) string
- func (agi *AGI) EnvArgs() []string
- func (agi *AGI) Exec(app, opts string) (Response, error)
- func (agi *AGI) GetData(file string, timeout, maxdigit int) (Response, error)
- func (agi *AGI) GetFullVariable(name, channel string) (Response, error)
- func (agi *AGI) GetOption(filename, digits string, timeout int32) (Response, error)
- func (agi *AGI) GetVariable(name string) (Response, error)
- func (agi *AGI) Hangup(channel ...string) (Response, error)
- func (agi *AGI) IsHungup() bool
- func (agi *AGI) ReceiveChar(timeout int) (Response, error)
- func (agi *AGI) ReceiveText(timeout int) (Response, error)
- func (agi *AGI) RecordFile(file, format, escDigits string, timeout, offset int, beep bool, silence int) (Response, error)
- func (agi *AGI) SayAlpha(line, escDigits string) (Response, error)
- func (agi *AGI) SayDate(date, escDigits string) (Response, error)
- func (agi *AGI) SayDatetime(time, escDigits, format, timezone string) (Response, error)
- func (agi *AGI) SayDigits(number, escDigits string) (Response, error)
- func (agi *AGI) SayNumber(number, escDigits string) (Response, error)
- func (agi *AGI) SayPhonetic(str, escDigits string) (Response, error)
- func (agi *AGI) SayTime(time, escDigits string) (Response, error)
- func (agi *AGI) SendImage(image string) (Response, error)
- func (agi *AGI) SendText(text string) (Response, error)
- func (agi *AGI) SetAutoHangup(seconds int) (Response, error)
- func (agi *AGI) SetCallerid(clid string) (Response, error)
- func (agi *AGI) SetContext(ctx string) (Response, error)
- func (agi *AGI) SetExtension(ext string) (Response, error)
- func (agi *AGI) SetMusic(enable bool, class string) (Response, error)
- func (agi *AGI) SetPriority(priority string) (Response, error)
- func (agi *AGI) SetVariable(name, value string) (Response, error)
- func (agi *AGI) StreamFile(file, escDigits string, offset int) (Response, error)
- func (agi *AGI) TDDMode(mode string) (Response, error)
- func (agi *AGI) Verbose(msg string, level ...int) (Response, error)
- func (agi *AGI) WaitForDigit(timeout int) (Response, error)
- type Debugger
- type Error
- type Reader
- type Response
- type Writer
ErrAGI goagi error
var ErrAGI = newError("AGI session")
type AGI
AGI object
type AGI struct {
// contains filtered or unexported fields
}
func New
func New(r Reader, w Writer, dbg Debugger) (*AGI, error)
New creates and returns AGI object. Can be used to create agi and fastagi sessions.
Parameters:
- Reader that implements Read method
- Writer that implements Write method
- Debugger that allows to deep library debugging. Nil for production.
func (*AGI) Answer
func (agi *AGI) Answer() (Response, error)
Answer executes AGI command "ANSWER" Answers channel if not already in answer state.
func (*AGI) AsyncAGIBreak
func (agi *AGI) AsyncAGIBreak() (Response, error)
AsyncAGIBreak Interrupts Async AGI Interrupts expected flow of Async AGI commands and returns control to previous source (typically, the PBX dialplan).
func (*AGI) ChannelStatus
func (agi *AGI) ChannelStatus(channel string) (Response, error)
ChannelStatus returns status of the connected channel.
If no channel name is given (empty line) then returns the status of the current channel.
Return values:
0 - Channel is down and available.
1 - Channel is down, but reserved.
2 - Channel is off hook.
3 - Digits (or equivalent) have been dialed.
4 - Line is ringing.
5 - Remote end is ringing.
6 - Line is up.
7 - Line is busy.
func (*AGI) Command
func (agi *AGI) Command(cmd string) (Response, error)
Command sends command as string to the AGI and returns response values with text response
func (*AGI) ControlStreamFile
func (agi *AGI) ControlStreamFile(filename, digits string, args ...string) (Response, error)
ControlStreamFile sends audio file on channel and allows the listener to control the stream. Send the given file, allowing playback to be controlled by the given digits, if any. Use double quotes for the digits if you wish none to be permitted. If offsetms is provided then the audio will seek to offsetms before play starts.
Example:
agi.ControlStreamFile("prompt_en", "19", "3000", "#", "0", "#", "1600")
agi.ControlStreamFile("prompt_en", "")
agi.ControlStreamFile("prompt_en", "19", "", "", "", "#", "1600")
func (*AGI) DatabaseDel
func (agi *AGI) DatabaseDel(family, key string) (Response, error)
DatabaseDel deletes an entry in the Asterisk database for a given family and key. Returns status and error if fails.
func (*AGI) DatabaseDelTree
func (agi *AGI) DatabaseDelTree(family, keytree string) (Response, error)
DatabaseDelTree deletes a family or specific keytree within a family in the Asterisk database.
func (*AGI) DatabaseGet
func (agi *AGI) DatabaseGet(family, key string) (Response, error)
DatabaseGet Retrieves an entry in the Asterisk database for a given family and key. Returns value as string or error if failed or value not set Response.Value() for result
func (*AGI) DatabasePut
func (agi *AGI) DatabasePut(family, key, val string) (Response, error)
DatabasePut adds or updates an entry in the Asterisk database for a given family, key, and value.
func (*AGI) Env
func (agi *AGI) Env(key string) string
Env returns AGI environment variable by key
func (*AGI) EnvArgs
func (agi *AGI) EnvArgs() []string
EnvArgs returns list of environment arguments
func (*AGI) Exec
func (agi *AGI) Exec(app, opts string) (Response, error)
Exec executes application with given options.
func (*AGI) GetData
func (agi *AGI) GetData(file string, timeout, maxdigit int) (Response, error)
GetData Stream the given file, and receive DTMF data. Note: when timeout is 0 then Asterisk will use 6 seconds. Note: Asterisk has strange way to handle get data response. Contrary to other responses, where result has numeric value, here asterisk puts DTMF to sent by user to result and this value may contain "#" and "*".
To get DTMF sent by user use Response.Data()
Response.Value() will contain "timeout" if user has not terminated input with "#"
func (*AGI) GetFullVariable
func (agi *AGI) GetFullVariable(name, channel string) (Response, error)
GetFullVariable evaluates a channel expression
func (*AGI) GetOption
func (agi *AGI) GetOption(filename, digits string, timeout int32) (Response, error)
GetOption Stream file, prompt for DTMF, with timeout. Behaves similar to STREAM FILE but used with a timeout option. Returns digit pressed, offset and error
func (*AGI) GetVariable
func (agi *AGI) GetVariable(name string) (Response, error)
GetVariable Gets a channel variable.
func (*AGI) Hangup
func (agi *AGI) Hangup(channel ...string) (Response, error)
Hangup hangs up the specified channel. If no channel name is given, hangs up the current channel
func (*AGI) IsHungup
func (agi *AGI) IsHungup() bool
IsHungup returns true if AGI channel received HANGUP signal
func (*AGI) ReceiveChar
func (agi *AGI) ReceiveChar(timeout int) (Response, error)
ReceiveChar Receives one character from channels supporting it. Most channels do not support the reception of text. Returns the decimal value of the character if one is received, or 0 if the channel does not support text reception.
timeout - The maximum time to wait for input in milliseconds, or 0 for infinite.
Returns result -1 on error or char byte
func (*AGI) ReceiveText
func (agi *AGI) ReceiveText(timeout int) (Response, error)
ReceiveText Receives text from channels supporting it.
timeout - The timeout to be the maximum time to wait for input in milliseconds, or 0 for infinite.
func (*AGI) RecordFile
func (agi *AGI) RecordFile(file, format, escDigits string,
timeout, offset int, beep bool, silence int) (Response, error)
RecordFile Record to a file until a given dtmf digit in the sequence is received. The format will specify what kind of file will be recorded. The timeout is the maximum record time in milliseconds, or -1 for no timeout.
offset samples is optional, and, if provided, will seek to the offset without exceeding the end of the file.
beep causes Asterisk to play a beep to the channel that is about to be recorded.
silence is the number of seconds of silence allowed before the function returns despite the lack of dtmf digits or reaching timeout.
silence is the number of seconds of silence that are permitted before the recording is terminated, regardless of the escape_digits or timeout arguments
If interrupted by DTMF, digits will be available in Response.Data()
func (*AGI) SayAlpha
func (agi *AGI) SayAlpha(line, escDigits string) (Response, error)
SayAlpha says a given character string, returning early if any of the given DTMF digits are received on the channel.
func (*AGI) SayDate
func (agi *AGI) SayDate(date, escDigits string) (Response, error)
SayDate say a given date, returning early if any of the given DTMF digits are received on the channel
func (*AGI) SayDatetime
func (agi *AGI) SayDatetime(time, escDigits, format, timezone string) (Response, error)
SayDatetime say a given time, returning early if any of the given DTMF digits are received on the channel
func (*AGI) SayDigits
func (agi *AGI) SayDigits(number, escDigits string) (Response, error)
SayDigits say a given digit string, returning early if any of the given DTMF digits are received on the channel
func (*AGI) SayNumber
func (agi *AGI) SayNumber(number, escDigits string) (Response, error)
SayNumber say a given digit string, returning early if any of the given DTMF digits are received on the channel
func (*AGI) SayPhonetic
func (agi *AGI) SayPhonetic(str, escDigits string) (Response, error)
SayPhonetic say a given character string with phonetics, returning early if any of the given DTMF digits are received on the channel
func (*AGI) SayTime
func (agi *AGI) SayTime(time, escDigits string) (Response, error)
SayTime say a given time, returning early if any of the given DTMF digits are received on the channel
func (*AGI) SendImage
func (agi *AGI) SendImage(image string) (Response, error)
SendImage Sends the given image on a channel. Most channels do not support the transmission of images.
func (*AGI) SendText
func (agi *AGI) SendText(text string) (Response, error)
SendText Sends the given text on a channel. Most channels do not support the transmission of text.
func (*AGI) SetAutoHangup
func (agi *AGI) SetAutoHangup(seconds int) (Response, error)
SetAutoHangup Cause the channel to automatically hangup at time seconds in the future. Setting to 0 will cause the autohangup feature to be disabled on this channel.
func (*AGI) SetCallerid
func (agi *AGI) SetCallerid(clid string) (Response, error)
SetCallerid Changes the callerid of the current channel.
func (*AGI) SetContext
func (agi *AGI) SetContext(ctx string) (Response, error)
SetContext Sets the context for continuation upon exiting the application.
func (*AGI) SetExtension
func (agi *AGI) SetExtension(ext string) (Response, error)
SetExtension Changes the extension for continuation upon exiting the application.
func (*AGI) SetMusic
func (agi *AGI) SetMusic(enable bool, class string) (Response, error)
SetMusic Enables/Disables the music on hold generator. If class is not specified, then the default music on hold class will be used.
func (*AGI) SetPriority
func (agi *AGI) SetPriority(priority string) (Response, error)
SetPriority Changes the priority for continuation upon exiting the application. The priority must be a valid priority or label.
func (*AGI) SetVariable
func (agi *AGI) SetVariable(name, value string) (Response, error)
SetVariable Sets a variable to the current channel.
func (*AGI) StreamFile
func (agi *AGI) StreamFile(file, escDigits string, offset int) (Response, error)
StreamFile Send the given file, allowing playback to be interrupted by the given digits, if any.
func (*AGI) TDDMode
func (agi *AGI) TDDMode(mode string) (Response, error)
TDDMode Enable/Disable TDD transmission/reception on a channel. Modes: on, off, mate, tdd
func (*AGI) Verbose
func (agi *AGI) Verbose(msg string, level ...int) (Response, error)
Verbose Sends message to the console via verbose message system. level is the verbose level (1-4)
func (*AGI) WaitForDigit
func (agi *AGI) WaitForDigit(timeout int) (Response, error)
WaitForDigit Waits up to timeout *milliseconds* for channel to receive a DTMF digit. Use -1 for the timeout value if you desire the call to block indefinitely.
Return digit pressed as string or error
type Debugger
Debugger for AGI instance. Any interface that provides Printf method. It should be used only for debugging as it give lots of output.
type Debugger interface {
Printf(format string, v ...interface{})
}
type Error
Error object for goagi library
type Error struct {
// contains filtered or unexported fields
}
func (*Error) Error
func (e *Error) Error() string
Error message for the Error object
func (*Error) Msg
func (e *Error) Msg(msg string, args ...interface{}) error
Msg append message to main context message
type Reader
Reader interface for AGI object. Can be net.Conn, os.File or crafted
type Reader interface {
Read(b []byte) (int, error)
}
type Response
Response interface that all commands return. Helps to access different parts of AGI response
type Response interface {
// Code of response: 200, 510 etc
Code() int
// RawResponse return full text of AGI response
RawResponse() string
// Result returns value of result= field
Result() int
// Value returns value field: (timeout)
Value() string
// Data returns text for error responses and dtmf values for command like GetData
Data() string
// EndPos returns value for endpos= field
EndPos() int64
// Digit return digit from digit= field
Digit() string
// SResults return value for results= field
SResults() int
}
type Writer
Writer interface for AGI object. Can be net.Conn, os.File or crafted
type Writer interface {
Write(b []byte) (int, error)
}
Generated by gomarkdoc