Installation
composer require bestnetwork/2n-voiceblue
Add the service provider to config/app.php:
BestNetwork\Voiceblue\VoiceblueServiceProvider::class,
Configuration Publish the config file:
php artisan vendor:publish --provider="BestNetwork\Voiceblue\VoiceblueServiceProvider"
Update config/voiceblue.php with your gateway credentials (IP, port, username, password).
First Use Case: Basic Call Initiation
Inject the Voiceblue facade or service into a controller:
use BestNetwork\Voiceblue\Facades\Voiceblue;
public function makeCall()
{
$call = Voiceblue::call('1234567890', 'extension123');
return response()->json($call);
}
Call Management
$call = Voiceblue::call('destinationNumber', 'sourceExtension');
Voiceblue::hangup($callId);
$activeCalls = Voiceblue::activeCalls();
Extension Management
Voiceblue::registerExtension('extension123', ['name' => 'John Doe']);
Voiceblue::unregisterExtension('extension123');
Event Listeners
Use Laravel’s event system to listen for gateway events (e.g., CallStarted, CallEnded):
Voiceblue::listen('call.started', function ($event) {
Log::info('Call started: ' . $event->callId);
});
Integration with Queues Offload call operations to queues for async processing:
Voiceblue::dispatch(new InitiateCallJob('destination', 'extension'));
config/voiceblue.php for troubleshooting:
'debug' => env('VOICEBLUE_DEBUG', false),
try {
$call = Voiceblue::call('1234567890', 'extension123');
} catch (\BestNetwork\Voiceblue\Exceptions\GatewayException $e) {
Log::error($e->getMessage());
}
VoiceblueFake class for unit testing:
Voiceblue::fake()->shouldReceive('call')->once()->andReturn(['id' => 'test123']);
Connection Issues
config/voiceblue.php match the gateway settings.telnet to the gateway port to confirm connectivity:
telnet <gateway-ip> <gateway-port>
Rate Limiting The gateway may throttle requests. Implement exponential backoff in retries:
use Illuminate\Support\Facades\Retry;
Retry::times(3)->backoff(100)->try(function () {
Voiceblue::call('destination', 'extension');
});
Extension States Extensions must be registered before making calls. Unregistered extensions will fail silently.
Timeouts Default timeout (30s) may be too short for slow networks. Adjust in config:
'timeout' => 60, // seconds
'log_level' => 'debug',
http://<gateway-ip>) for real-time events.dd() for Responses: Inspect raw responses from the gateway:
$response = Voiceblue::rawCall('destination', 'extension');
dd($response);
Custom Commands
Extend the VoiceblueManager to add custom commands:
Voiceblue::extend(function ($manager) {
$manager->addCommand('custom.command', function ($params) {
return $this->sendCommand('CUSTOM ' . json_encode($params));
});
});
Event Customization
Override default event classes in config/voiceblue.php:
'events' => [
'call.started' => \App\Events\CustomCallStarted::class,
],
Middleware Add middleware to modify requests/responses globally:
Voiceblue::middleware(function ($request, $next) {
$request->header('X-Custom-Header', 'value');
return $next($request);
});
How can I help you explore Laravel packages today?