Posts Tagged ‘library’

Using the Asterisk Manager PHP API

July 19th, 2008

Well it’s been a while since the PHP Asterisk Manager API was released and I’ve yet to produce a clear and definitive example of its use.  So here goes.

Prerequisites

Your Asterisk server must be set up correctly before this API can ’speak’ to the server.

  • First you’ll need to ensure the Manager interface is active and you’ve set the correct permissions (If you’d like this explaining please leave a comment).
  • Secondly make sure you are setup with the ability for two endpoints to call each other.  This won’t work if you have one phone on the server.

Install

Firstly you’ll need to get hold of the library and there’s two routes to take.  You can either install via PEAR or simply checkout the source from the Google Project:

svn checkout http://asterisk-php-api.googlecode.com/svn/trunk/ asterisk-php-api

Originating a Call

Once you’ve got it all ready you need to start your new file thats going to make use of it.  In this example I’m creating a simple dialler called: “call.php” which will take two GET variables, with one being the callee and one the caller.

 '192.168.1.5',
  'port' => '5038',
  'auto_connect' => true
);

//Initialise
$am = new Net_AsteriskManager($params);

//Login to the Asterisk Manager interface
$am->login('user', 'pass');

//Originate Call is one of the commands available and it causes a call to be made and connected between two endpoints.
$am->originateCall($number, $from, $context, $cid, 1, 30000);
?>

By looking at the comments above you should see how this works and the steps required. If not then leave any comments and I’ll build on the above. It’s sometimes difficult to know what people already know so apologies if this is too simple or complex. :)

Later on I’ll show how to work with queues – adding, removing, listing, etc.

Asterisk Manager API [PHP]

March 15th, 2008

Asterisk LogoAgain with the PHP code! This time its a bit more exciting than a CakePHP component. If you’ve ever used Asterisk – an open source PBX – then you’ll know it comes with a manager interface which enables developers to send commands to the server to help administer the system and its connected peers and channels.

Visit the blog page for more info on the new PHP interface.