khody2012 / laravel-ami-toolkit
A powerful and developer-friendly Laravel package that provides seamless integration with Asterisk AMI (Asterisk Manager Interface).
Requires
- php: ^8.1
- illuminate/events: ^9.0 || ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^9.0 || ^10.0 || ^11.0 || ^12.0
- psr/log: ^3.0
- react/event-loop: ^1.5
- react/promise: ^2.9 || ^3.0
- react/socket: ^1.15
Requires (Dev)
- mockery/mockery: ^1.5
- orchestra/testbench: ^8.0 || ^9.0
- phpunit/phpunit: ^10.0 || ^11.0
README
π Laravel AMI Toolkit is a powerful, developer-friendly Laravel package for seamless integration with the Asterisk Manager Interface (AMI).
It provides clean abstractions and expressive APIs to connect to Asterisk, listen to AMI events, and send manager commands β all while staying idiomatic to Laravelβs ecosystem.
This package is designed for real-time, event-driven telephony applications such as CRMs, call centers, monitoring dashboards, and VoIP-based services.
β¨ Features
- π Persistent and configurable connection to Asterisk AMI
- π‘ Listen to real-time AMI events (Dial, Hangup, Queue, etc.)
- β‘ Send AMI actions (Originate, Hangup, Ping, Command, β¦)
- π§© Laravel Event & Listener integration
- π§ͺ Testable architecture with mockable components
- π οΈ Clean, extensible, and well-structured codebase
- π Secure authentication handling
- π¦ Laravel auto-discovery support
π¦ Installation
Install the package via Composer:
composer require khody2012/laravel-ami-toolkit
β‘ Requirements
- PHP 8.1+
- Laravel 9.x, 10.x, 11.x, 12.x
βοΈ Configuration
Publish the configuration file:
php artisan vendor:publish --tag=ami-config
This will create config/ami.php.
Example configuration
return [ 'host' => env('AMI_HOST', '127.0.0.1'), 'port' => env('AMI_PORT', 5038), 'username' => env('AMI_USERNAME'), 'password' => env('AMI_PASSWORD'), 'timeout' => 5, 'auto_reconnect' => true, ];
Add the following variables to your .env file:
AMI_HOST=127.0.0.1 AMI_PORT=5038 AMI_USERNAME=admin AMI_PASSWORD=secret
π Basic Usage
Connecting to Asterisk AMI
use Khody2012\LaravelAmiToolkit\Facades\Ami; Ami::connect(); $response = Ami::ping(); if ($response->isSuccess()) { // Connection alive }
π AMI Actions
Originate a Call
Ami::originate([ 'Channel' => 'SIP/1000', 'Context' => 'default', 'Exten' => '1001', 'Priority' => 1, 'Timeout' => 30000, ]);
Execute a raw AMI command
Ami::command('sip show peers');
Available Events (examples)
AmiDialEventAmiHangupEventAmiNewChannelEventAmiQueueMemberEventAmiBridgeEvent
You can easily extend or map new AMI events.
π§© Architecture Overview
- Connection Layer β Handles socket communication and authentication
- Action Layer β Encapsulates AMI actions
- Event Layer β Maps AMI events to Laravel events
- Facade API β Clean developer-facing interface
This layered design keeps the package maintainable, testable, and extensible.
π Security Notes
- Credentials are never logged
- Supports environment-based configuration
- Connection timeouts and reconnection strategies included
π£οΈ Roadmap
- Async / non-blocking event loop
- Queue-based event handling
- Horizon & WebSocket integration
- Dashboard helpers
- Full API documentation website
π€ Contributing
Contributions are welcome β€οΈ
- Fork the repository
- Create a feature branch
- Write tests
- Submit a pull request
π License
This package is open-sourced software licensed under the MIT license.
π·οΈ Keywords
laravel, asterisk, ami, voip, pbx, telephony, event-driven, call-center, realtime