FreePBX Open Source - Asterisk Manager Class
Table of Contents
- 1 Initial Setup
- 2 List of Commands
- 2.1 Check if Asterisk is connected
- 2.2 Set Absolute Timeout
- 2.3 Execute Command
- 2.4 Check Extension Status
- 2.5 Get Channel Variable
- 2.6 Set Channel Variable
- 2.7 MessageSend
- 2.8 Codecs
- 2.9 ConfbridgeKick
- 2.10 ConfbridgeList
- 2.11 ConfbridgeListRooms
- 2.12 ConfbridgeLock
- 2.13 ConfbridgeMute
- 2.14 ConfbridgeSetSingleVideoSrc
- 2.15 ConfbridgeStartRecord
- 2.16 ConfbridgeStopRecord
- 2.17 ConfbridgeUnlock
- 2.18 ConfbridgeUnmute
- 2.19 MeetmeList
- 2.20 MeetmeListRooms
- 2.21 MeetmeMute
- 2.22 MeetmeUnmute
- 2.23 Hangup Channel
- 2.24 List IAX Peers
- 2.25 List available manager commands
- 2.26 Check Mailbox Message Count
- 2.27 Check Mailbox
- 2.28 Monitor a channel
- 2.29 Originate Call
- 2.30 List Parked Calls
- 2.31 Queue Add
- 2.32 Queue Remove
- 2.33 Queues
- 2.34 Queue Status
- 2.35 Redirect
- 2.36 List SIP Peers
- 2.37 Channel Status
- 2.38 Stop monitoring a channel
- 2.39 Log a message
- 2.40 Add event handler
- 2.41 Enable/Disable Sending of events to this manager
- 2.42 Process Event
- 2.43 Show All Database Entries (Or by Family)
- 2.44 Add an Entry to the Asterisk Database
- 2.45 Get an entry from the asterisk database
- 2.46 Delete an entry from the asterisk database
- 2.47 Delete a family from the asterisk database
- 2.48 Function Exists
- 2.49 Application Exists
- 2.50 Module Loaded
- 2.51 Set Global Variable
- 2.52 Reload
- 2.53 Start Mixmonitor
- 2.54 Stop Mixmonitor
The asterisk manager class (Stored in the global variable $astman) allows a module to directly access and manipulate Asterisk.
Initial Setup
The Asterisk Manager Class can be initiated in FreePBX by first running
global $astman;Once this is done you will have full access to the asterisk manager list of commands below:
List of Commands
Check if Asterisk is connected
/**
* Check if the socket is connected
* @return boolean True if connected. False if not
*/
$astman->connected();Set Absolute Timeout
/**
* Set Absolute Timeout
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+AbsoluteTimeout
* @param string $channel
* @param integer $timeout
*/
$astman->AbsoluteTimeout($channel, $timeout);Execute Command
/**
* Execute Command
*
* @example examples/sip_show_peer.php Get information about a sip peer
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Command
* @link http://www.voip-info.org/wiki-Asterisk+CLI
* @param string $command
* @param string $actionid message matching variable
*/
$astman->Command($command, $actionid=NULL);Check Extension Status
/**
* Check Extension Status
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ExtensionState
* @param string $exten Extension to check state on
* @param string $context Context for extension
* @param string $actionid message matching variable
*/
$astman->ExtensionState($exten, $context, $actionid = NULL);Get Channel Variable
/**
* Gets a Channel Variable
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+GetVar
* @param string $channel Channel to read variable from
* @param string $variable
* @param string $actionid message matching variable
*/
$astman->GetVar($channel, $variable, $actionid=NULL);Set Channel Variable
/**
* Set Channel Variable
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetVar
* @param string $channel Channel to set variable for
* @param string $variable name
* @param string $value
*/
$astman->SetVar($channel, $variable, $value);MessageSend
/**
* MessageSend
*
* Send an SMS message
*
* @param string $to
* @param string $from
* @param string $body
* @param string $variable optional
* @returns array result of send_request
*/
$astman->MessageSend($to, $from, $body, $variable=null);Codecs
/**
* Get and parse codecs
* @param {string} $type='audio' Type of codec to look up (can be: audio,video,text,image)
*/
$asman->Codecs($type='audio');ConfbridgeKick
/**
* Kick a Confbridge user.
*
* Kick a Confbridge user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeKick
* @param string $conference Conference number.
* @param string $channel If this parameter is not a complete channel name, the first channel with this prefix will be used.
*/
$asman->ConfbridgeKick($conference, $channel);ConfbridgeList
/**
* List Users in a Conference
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeList
* @param string $conference Conference number.
*/
$asman->ConfbridgeList($conference);ConfbridgeListRooms
/**
* List active conferences.
*
* Lists data about all active conferences. ConfbridgeListRooms will follow as separate events, followed by a final event called ConfbridgeListRoomsComplete.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeListRooms
*/
$asman->ConfbridgeListRooms()ConfbridgeLock
/**
* Lock a Confbridge conference.
*
* Lock a Confbridge conference.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeLock
* @param string $conference Conference number.
*/
$asman->ConfbridgeLock($conference)ConfbridgeMute
/**
* Mute a Confbridge user.
*
* Mute a Confbridge user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeMute
* @param string $conference Conference number.
* @param string $channel If this parameter is not a complete channel name, the first channel with this prefix will be used.
*/
$astman->ConfbridgeMute($conference,$channel);ConfbridgeSetSingleVideoSrc
/**
* Set a conference user as the single video source distributed to all other participants.
*
* Set a conference user as the single video source distributed to all other participants.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeSetSingleVideoSrc
* @param string $conference Conference number.
* @param string $channel If this parameter is not a complete channel name, the first channel with this prefix will be used.
*/
$astman->ConfbridgeSetSingleVideoSrc($conference,$channel);ConfbridgeStartRecord
/**
* Start recording a Confbridge conference.
*
* Start recording a conference. If recording is already present an error will be returned.
* If RecordFile is not provided, the default record file specified in the conference's bridge profile will be used, if that is not present either a file will automatically be generated in the monitor directory.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeMute
* @param string $conference Conference number.
* @param string $channel If this parameter is not a complete channel name, the first channel with this prefix will be used.
*/
$astman->ConfbridgeStartRecord($conference,$recordFile);ConfbridgeStopRecord
/**
* Stop recording a Confbridge conference.
*
* Stop recording a Confbridge conference.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeStopRecord
* @param string $conference Conference number.
*/
$astman->ConfbridgeStopRecord($conference);ConfbridgeUnlock
/**
* Unlock a Confbridge conference.
*
* Unlock a Confbridge conference.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeUnlock
* @param string $conference Conference number.
*/
$astman->ConfbridgeUnlock($conference);ConfbridgeUnmute
/**
* Unmute a Confbridge user.
*
* Unmute a Confbridge user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeUnmute
* @param string $conference Conference number.
*/
$astman->ConfbridgeUnmute($conference,$channel);MeetmeList
/**
* List participants in a conference.
*
* Lists all users in a particular MeetMe conference. MeetmeList will follow as separate events, followed by a final event called MeetmeListComplete.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_MeetmeList
* @param string $conference Conference number.
*/
$astman->MeetmeList($conference);MeetmeListRooms
/**
* List active conferences.
*
* Lists data about all active conferences. MeetmeListRooms will follow as separate events, followed by a final event called MeetmeListRoomsComplete.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_ConfbridgeListRooms
*/
$astman->MeetmeListRooms()MeetmeMute
/**
* Mute a Meetme user.
*
* Mute a Meetme user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_MeetmeMute
* @param string $meetme Conference number.
* @param string $usernum User Number
*/
$astman->MeetmeMute($meetme,$usernum);MeetmeUnmute
/**
* Unmute a Meetme user.
*
* Unmute a Meetme user.
*
* @link https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+ManagerAction_MeetmeUnmute
* @param string $meetme Conference number.
* @param string $usernum User Number
*/
$astman->MeetmeUnmute($meetme,$usernum);Hangup Channel
/**
* Hangup Channel
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Hangup
* @param string $channel The channel name to be hungup
*/
$astman->Hangup($channel);List IAX Peers
/**
* List IAX Peers
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+IAXpeers
*/
$astman->IAXPeers();List available manager commands
/**
* List available manager commands
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ListCommands
* @param string $actionid message matching variable
*/
$astman->ListCommands($actionid=NULL)Check Mailbox Message Count
/**
* Check Mailbox Message Count
*
* Returns number of new and old messages.
* Message: Mailbox Message Count
* Mailbox: <mailboxid>
* NewMessages: <count>
* OldMessages: <count>
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxCount
* @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
*/
$astman->MailboxCount($mailbox, $actionid=NULL);Check Mailbox
/**
* Check Mailbox
*
* Returns number of messages.
* Message: Mailbox Status
* Mailbox: <mailboxid>
* Waiting: <count>
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxStatus
* @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
* @param string $actionid message matching variable
*/
$astman->MailboxStatus($mailbox, $actionid=NULL);Monitor a channel
/**
* Monitor a channel
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Monitor
* @param string $channel
* @param string $file
* @param string $format
* @param boolean $mix
*/
$astman->Monitor($channel, $file=NULL, $format=NULL, $mix=NULL);Originate Call
/**
* Originate Call
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Originate
* @param string $channel
* @param string $exten
* @param string $context
* @param string $priority
* @param integer $timeout
* @param string $callerid
* @param string $variable
* @param string $account
* @param string $application
* @param string $data
* == exactly 11 values required ==
*
* -- OR --
*
* @pram array a key => value array of what ever you want to pass in
*/
$astman->Originate();List Parked Calls
/**
* List parked calls
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ParkedCalls
*/
$astman->ParkedCalls($actionid=NULL);Queue Add
/**
* Queue Add
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueAdd
* @param string $queue
* @param string $interface
* @param integer $penalty
*/
$astman->QueueAdd($queue, $interface, $penalty=0);Queue Remove
/**
* Queue Remove
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueRemove
* @param string $queue
* @param string $interface
*/
$astman->QueueRemove($queue, $interface);Queues
/**
* Queues
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Queues
*/
$astman->Queues();Queue Status
/**
* Queue Status
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueStatus
* @param string $actionid message matching variable
*/
$astman->QueueStatus($actionid=NULL);Redirect
/**
* Redirect
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Redirect
* @param string $channel
* @param string $extrachannel
* @param string $exten
* @param string $context
* @param string $priority
*/
$astman->Redirect($channel, $extrachannel, $exten, $context, $priority);List SIP Peers
$astman->SIPpeers();Channel Status
/* Channel Status
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Status
* @param string $channel
* @param string $actionid message matching variable
*/
$astman->Status($channel, $actionid=NULL);Stop monitoring a channel
/**
* Stop monitoring a channel
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+StopMonitor
* @param string $channel
*/
$astman->StopMonitor($channel);Log a message
/*
* Log a message
*
* @param string $message
* @param integer $level from 1 to 4
*/
$astman->log($message, $level = 1);Add event handler
/**
* Add event handler
*
* Known Events include ( http://www.voip-info.org/wiki-asterisk+manager+events )
* Link - Fired when two voice channels are linked together and voice data exchange commences.
* Unlink - Fired when a link between two voice channels is discontinued, for example, just before call completion.
* Newexten -
* Hangup -
* Newchannel -
* Newstate -
* Reload - Fired when the "RELOAD" console command is executed.
* Shutdown -
* ExtensionStatus -
* Rename -
* Newcallerid -
* Alarm -
* AlarmClear -
* Agentcallbacklogoff -
* Agentcallbacklogin -
* Agentlogoff -
* MeetmeJoin -
* MessageWaiting -
* join -
* leave -
* AgentCalled -
* ParkedCall - Fired after ParkedCalls
* Cdr -
* ParkedCallsComplete -
* QueueParams -
* QueueMember -
* QueueStatusEnd -
* Status -
* StatusComplete -
* ZapShowChannels - Fired after ZapShowChannels
* ZapShowChannelsComplete -
*
* @param string $event type or * for default handler
* @param string $callback function
* @return boolean sucess
*/
$astman->add_event_handler($event, $callback);Enable/Disable Sending of events to this manager
/**
* Enable/Disable sending of events to this manager
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Events
* @param string $eventmask is either 'on', 'off', or 'system,call,log'
*/
$astman->Events($eventmask);Process Event
/**
* Process event
*
* @access private
* @param array $parameters
* @return mixed result of event handler or false if no handler was found
*/
$astman->process_event($parameters);Show All Database Entries (Or by Family)
/** Show all entries in the asterisk database
* @return Array associative array of key=>value
*/
$astman->database_show($family='')Add an Entry to the Asterisk Database
/** Add an entry to the asterisk database
* @param string $family The family name to use
* @param string $key The key name to use
* @param mixed $value The value to add
* @return bool True if successful
*/
$astman->database_put($family, $key, $value)Get an entry from the asterisk database
/** Get an entry from the asterisk database
* @param string $family The family name to use
* @param string $key The key name to use
* @return mixed Value of the key, or false if error
*/
$astman->database_get($family, $key);Delete an entry from the asterisk database
/** Delete an entry from the asterisk database
* @param string $family The family name to use
* @param string $key The key name to use
* @return bool True if successful
*/
$astman->database_del($family, $key)Delete a family from the asterisk database
/** Delete a family from the asterisk database
* @param string $family The family name to use
* @return bool True if successful
*/
$astman->database_deltree($family)Function Exists
/** Returns whether a give function exists in this Asterisk install
* @param string $func The case sensitve name of the function
* @return bool True if if it exists
*/
$astman->func_exists($func)Application Exists
/** Returns whether a give application exists in this Asterisk install
* @param string $app The case in-sensitve name of the application
* @return bool True if if it exists
*/
$astman->app_exists($app)Module Loaded
/** Returns whether a give asterisk module is loaded in this Asterisk install
* @param string $app The case in-sensitve name of the application
* @return bool True if if it exists
*/
$astman->mod_loaded($mod)Set Global Variable
/** Sets a global var or function to the provided value
* @param string $var The variable or function to set
* @param string $val the value to set it to
* @return array returns the array value from the send_request
*/
$astman->set_global($var, $val)Reload
/**
* Reload module(s)
*
* @link http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Reload
* @param string $module
* @param string $actionid
*/
$astman->Reload($module=NULL, $actionid=NULL)Start Mixmonitor
/** Starts mixmonitor
* @param string $channel The channel to start recording
* @param string $file The file to record to
* @param string $options Options to pass to mixmonitor
* @param string $postcommand Command to execute after recording
* @param string $actionid message matching variable
*
* @return array returns the array value from the send_request
*/
$astman->mixmonitor($channel, $file, $options='', $postcommand='', $actionid=NULL)Stop Mixmonitor
/** Stops mixmonitor
* @param string $channel The channel to stop recording
* @param string $actionid message matching variable
*
* @return array returns the array value from the send_request
*/
$astman->stopmixmonitor($channel, $actionid=NULL)