PAGI\Client\AbstractClient

An abstract AGI client.

PHP Version 5

  • Class name: AbstractClient
  • Namespace: PAGI\Client
  • This is an abstract class
  • This class implements: PAGI\Client\IClient

Properties

$logger

protected \Psr\Log\LoggerInterface $logger

PSR-3 logger.

  • Visibility: protected

$variables

protected array<mixed,string> $variables = array()

Initial channel variables given by asterisk at start.

  • Visibility: protected

$arguments

protected array<mixed,string> $arguments = array()

Initial arguments given by the user in the dialplan.

  • Visibility: protected

$cdrInstance

protected mixed $cdrInstance = false
  • Visibility: protected

$channelVariablesInstance

protected mixed $channelVariablesInstance = false
  • Visibility: protected

$clidInstance

protected mixed $clidInstance = false
  • Visibility: protected

Methods

send

\PAGI\Client\Result\Result PAGI\Client\AbstractClient::send(string $text)

Sends a command to asterisk. Returns an array with: [0] => AGI Result (3 digits) [1] => Command result [2] => Result data.

  • Visibility: protected
  • This method is abstract.

Arguments

  • $text string - <p>Command</p>

open

void PAGI\Client\AbstractClient::open()

Opens connection to agi. Will also read initial channel variables given by asterisk when launching the agi.

  • Visibility: protected
  • This method is abstract.

close

void PAGI\Client\AbstractClient::close()

Closes the connection to agi.

  • Visibility: protected
  • This method is abstract.

getResultFromResultString

\PAGI\Client\Result\Result PAGI\Client\AbstractClient::getResultFromResultString(\PAGI\Client\unknown_type $text)

Returns a result object given a string (the agi result after executing a command).

  • Visibility: protected

Arguments

  • $text PAGI\Client\unknown_type

amd

\PAGI\Client\Result\AmdResult PAGI\Client\IClient::amd(array<mixed,string> $options)

Runs the AMD() application. For a complete list of options see: https://wiki.asterisk.org/wiki/display/AST/Application_AMD

Arguments

  • $options array<mixed,string>

faxSend

\PAGI\Client\Result\FaxResult PAGI\Client\IClient::faxSend(string $tiffFile)

Sends a fax.

Arguments

  • $tiffFile string - <p>Absolute path to a .tiff file.</p>

faxReceive

\PAGI\Client\Result\FaxResult PAGI\Client\IClient::faxReceive(string $tiffFile)

Receives a fax.

Arguments

  • $tiffFile string - <p>Absolute path to a .tiff file.</p>

dial

\PAGI\Client\Result\DialResult PAGI\Client\IClient::dial(string $channel, array<mixed,string> $options)

Tries to dial the given channel.

Arguments

  • $channel string - <p>What to dial.</p>
  • $options array<mixed,string> - <p>Dial app options</p>

exec

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::exec(string $application, array<mixed,string> $options)

Executes an application. Uses agi command "EXEC".

Arguments

  • $application string - <p>Application name.</p>
  • $options array<mixed,string> - <p>Application arguments.</p>

setAutoHangup

void PAGI\Client\IClient::setAutoHangup(integer $time)

Cause the channel to automatically hangup at

Of course it can be hungup before then as well. Setting to 0 will cause the autohangup feature to be disabled on this channel. Uses agi command "SET AUTOHANGUP".

Arguments

  • $time integer - <p>Time to hangup channel.</p>

channelStatus

integer PAGI\Client\IClient::channelStatus(string $channel)

Retrieves channel status. Uses agi command "CHANNEL STATUS"

Arguments

  • $channel string - <p>Optional, channel name.</p>

streamFile

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::streamFile(string $file, string $escapeDigits)

Plays a file, can be interrupted by escapeDigits.

Uses agi command "STREAM FILE"

Arguments

  • $file string - <p>File to play, without .wav extension.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>

record

\PAGI\Client\Result\RecordResult PAGI\Client\IClient::record(string $file, string $format, string $escapeDigits, integer $maxRecordTime, integer $silence)

Record to a file until are received as dtmf.

Uses agi command "RECORD FILE".

Arguments

  • $file string - <p>Target file, without the .wav (or extension chosen).</p>
  • $format string - <p>Format (wav, mp3, etc).</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>
  • $maxRecordTime integer - <p>Maximum record time (optional).</p>
  • $silence integer - <p>Maximum time of silence allowed (optional)</p>

setPriority

void PAGI\Client\IClient::setPriority(string $priority)

Changes the priority for continuation upon exiting the application.

Uses agi command "SET PRIORITY".

Arguments

  • $priority string - <p>New priority.</p>

setExtension

void PAGI\Client\IClient::setExtension(string $extension)

Changes the extension for continuation upon exiting the application.

Uses agi command "SET EXTENSION".

Arguments

  • $extension string - <p>New extension.</p>

setContext

void PAGI\Client\IClient::setContext(string $context)

Changes the context for continuation upon exiting the application.

Uses agi command "SET CONTEXT".

Arguments

  • $context string - <p>New context.</p>

setCallerId

void PAGI\Client\IClient::setCallerId(string $name, string $number)

Changes the callerid of the current channel. Uses agi command "SET CALLERID"

Arguments

  • $name string - <p>CallerId name.</p>
  • $number string - <p>CallerId number.</p>

setMusic

void PAGI\Client\IClient::setMusic(boolean $enable, string $class)

Enables/Disables the music on hold generator. Uses agi command "SET MUSIC".

Arguments

  • $enable boolean - <p>True to enable, false to disable.</p>
  • $class string - <p>If <class> is not specified then the default music on hold class will be used.</p>

getData

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::getData(string $file, integer $maxTime, string $maxDigits)

Reads input from user. Uses agi command "GET DATA".

Arguments

  • $file string - <p>File to play.</p>
  • $maxTime integer - <p>Maximum time between digits before timeout.</p>
  • $maxDigits string - <p>Maximum number of digits expected.</p>

getOption

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::getOption(string $file, string $escapeDigits, integer $maxTime)

Reads input from user. Uses agi command "GET OPTION".

Arguments

  • $file string - <p>File to play.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>
  • $maxTime integer - <p>Maximum time between digits before timeout.</p>

sayTime

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::sayTime(integer $time, string $escapeDigits)

Says time. Uses agi command "SAY TIME".

Arguments

  • $time integer - <p>Unix timestamp.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>

sayDate

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::sayDate(integer $time, string $escapeDigits)

Say a given date, returning early if any of the given DTMF digits are received on the channel. Uses agi command "SAY DATE".

Arguments

  • $time integer - <p>Unix timestamp.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>

sayDateTime

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::sayDateTime(integer $time, string $format, string $escapeDigits)

Say a given date and time, returning early if any of the given DTMF digits are received on the channel. Uses agi command "SAY DATETIME".

Arguments

  • $time integer - <p>Unix timestamp.</p>
  • $format string - <p>Format the time should be said in.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>

sayDigits

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::sayDigits(string $digits, string $escapeDigits)

Says digits. Uses agi command "SAY DIGITS".

Arguments

  • $digits string - <p>Number to say.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>

sayNumber

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::sayNumber(string $digits, string $escapeDigits)

Says a number. Uses agi command "SAY NUMBER".

Arguments

  • $digits string - <p>Number to say.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>

sayAlpha

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::sayAlpha(string $what, string $escapeDigits)

Say a given character string, returning early if any of the given DTMF digits are received on the channel. Uses agi command "SAY PHONETIC".

Arguments

  • $what string - <p>What to say.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>

sayPhonetic

\PAGI\Client\Result\PlayResult PAGI\Client\IClient::sayPhonetic(string $what, string $escapeDigits)

Say a given character string with phonetics, returning early if any of the given DTMF digits are received on the channel.

Uses agi command "SAY PHONETIC".

Arguments

  • $what string - <p>What to say.</p>
  • $escapeDigits string - <p>Optional sequence of digits that can be used to skip the sound.</p>

playAndRead

mixed PAGI\Client\AbstractClient::playAndRead($cmd)
  • Visibility: private

Arguments

  • $cmd mixed

waitDigit

\PAGI\Client\Result\DigitReadResult PAGI\Client\IClient::waitDigit(integer $timeout)

Waits up to milliseconds for channel to receive a DTMF digit.

Uses agi command "WAIT FOR DIGIT".

Arguments

  • $timeout integer - <p>Milliseconds to wait. -1 to block indefinitely.</p>

answer

void PAGI\Client\IClient::answer()

Answers the current channel. Uses agi command "ANSWER".

hangup

void PAGI\Client\IClient::hangup()

Hangups the current channel. Uses agi command "HANGUP".

getVariable

string PAGI\Client\IClient::getVariable(string $name)

Returns a variable value. Uses agi command "GET VARIABLE". False if variable is not set.

Arguments

  • $name string - <p>Variable name.</p>

getFullVariable

string PAGI\Client\IClient::getFullVariable(string $name, string $channel)

Returns a variable value. Uses agi command "GET FULL VARIABLE". False if variable is not set.

Arguments

  • $name string - <p>Variable name.</p>
  • $channel string - <p>Optional channel name.</p>

setVariable

void PAGI\Client\IClient::setVariable(string $name, string $value)

Sets a variable. Uses agi command "SET VARIABLE".

Arguments

  • $name string - <p>Variable name.</p>
  • $value string - <p>Variable value.</p>

log

void PAGI\Client\IClient::log(string $msg, string $priority)

Logs to asterisk logger. Uses application LOG.

Arguments

  • $msg string - <p>Message to log.</p>
  • $priority string - <p>One of ERROR, WARNING, NOTICE, DEBUG, VERBOSE, DTMF</p>

consoleLog

void PAGI\Client\IClient::consoleLog(string $msg)

Logs to asterisk console. Uses agi command "VERBOSE".

Arguments

  • $msg string - <p>Message to log.</p>

getAsteriskLogger

\PAGI\Logger\Asterisk\IAsteriskLogger PAGI\Client\IClient::getAsteriskLogger()

Returns an asterisk logger facade.

databaseDel

void PAGI\Client\IClient::databaseDel(string $family, string $key)

Deletes an entry in the Asterisk database for a given family and key.

Uses agi command "DATABASE DEL".

Arguments

  • $family string - <p>Family for key.</p>
  • $key string - <p>Key name.</p>

databaseDeltree

void PAGI\Client\IClient::databaseDeltree(string $family, string $key)

Deletes a family or specific keytree withing a family in the Asterisk database.

Uses agi command "DATABASE DELTREE".

Arguments

  • $family string - <p>Family for key.</p>
  • $key string - <p>Optional key name.</p>

databaseGet

string PAGI\Client\IClient::databaseGet(string $family, string $key)

Retrieves an entry in the Asterisk database for a given family and key.

Uses agi command "DATABASE GET".

Arguments

  • $family string - <p>Family for key.</p>
  • $key string - <p>Key name.</p>

databasePut

void PAGI\Client\IClient::databasePut(string $family, string $key, string $value)

Adds or updates an entry in the Asterisk database for a given family, key, and value.

Uses agi command "DATABASE PUT".

Arguments

  • $family string - <p>Family for key.</p>
  • $key string - <p>Key name.</p>
  • $value string - <p>Value to set.</p>

sendText

void PAGI\Client\IClient::sendText(string $text)

Sends the given text on a channel. Uses agi command "SEND TEXT".

Arguments

  • $text string - <p>Text to send.</p>

sendImage

void PAGI\Client\IClient::sendImage(string $filename)

Sends the given image on a channel. Uses agi command "SEND IMAGE".

Arguments

  • $filename string - <p>Image absolute path to send.</p>

isEndOfEnvironmentVariables

boolean PAGI\Client\AbstractClient::isEndOfEnvironmentVariables(string $line)

Returns true if the current line marks the end of the environment variables.

  • Visibility: protected

Arguments

  • $line string

readEnvironmentVariable

void PAGI\Client\AbstractClient::readEnvironmentVariable(string $line)

Will read and save an environment variable as either a variable or an argument.

  • Visibility: protected

Arguments

  • $line string

getChannelVariables

\PAGI\ChannelVariables\IChannelVariables PAGI\Client\IClient::getChannelVariables()

Returns an instance of ChannelVariables to access agi variables.

getCDR

\PAGI\CDR\ICDR PAGI\Client\IClient::getCDR()

Returns a cdr facade.

getCallerId

\PAGI\Client\ICallerID PAGI\Client\IClient::getCallerId()

Returns a caller id facade.

indicateProgress

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::indicateProgress()

Indicates progress of a call, starting early audio.

indicateBusy

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::indicateBusy(integer $timeout)

Indicates busy and waits for hangup. Does not play a busy tone.

Arguments

  • $timeout integer - <p>Time in seconds to wait for hangup</p>

indicateCongestion

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::indicateCongestion(integer $timeout)

Indicates congestion and waits for hangup. Does not play a busy tone.

Arguments

  • $timeout integer - <p>Time in seconds to wait for hangup</p>

playDialTone

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::playDialTone()

Plays "Dial" tone, defined in indications.conf

playBusyTone

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::playBusyTone()

Plays "Busy" tone, defined in indications.conf

playCongestionTone

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::playCongestionTone()

Plays "Congestion" tone, defined in indications.conf

playTone

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::playTone(string $tone)

Plays a tone defined in indications.conf.

Arguments

  • $tone string - <p>Tone to play</p>

playCustomTones

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::playCustomTones(array<mixed,string> $frequencies)

Plays a customized frequency tone.

Arguments

  • $frequencies array<mixed,string> - <p>Frequencies for the tone: 425/50,0/50 or !950/330,!1400/330,!1800/330,0 etc.</p>

stopPlayingTones

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::stopPlayingTones()

Stop playing current played tones.

createNode

\PAGI\Node\Node PAGI\Client\IClient::createNode(string $name)

Convenient method to create a node.

Arguments

  • $name string

sipHeaderAdd

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::sipHeaderAdd(string $name, string $value)

Adds a SIP header to the first invite message in a dial command.

Arguments

  • $name string
  • $value string

sipHeaderRemove

\PAGI\Client\Result\ExecResult PAGI\Client\IClient::sipHeaderRemove(string $name)

Removes a header previously added with sipHeaderAdd.

Arguments

  • $name string

createNodeController

\PAGI\Node\NodeController PAGI\Client\IClient::createNodeController(string $name)

Creates a new node controller.

Arguments

  • $name string

setLogger

void PAGI\Client\IClient::setLogger(\PAGI\Client\Psr\Log\LoggerInterface $logger)

Sets the logger implementation.

Arguments

  • $logger PAGI\Client\Psr\Log\LoggerInterface - <p>The PSR3-Logger</p>