Asterisk Manager Class

Asterisk Manager Class

 

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)