digitonic/laravel-infobip
Laravel package that integrates Infobip messaging services into your app. Provides a simple API to send SMS and other Infobip communications, with configurable credentials and easy setup for common notification workflows.
Installation
composer require digitonic/laravel-infobip
Publish the config file:
php artisan vendor:publish --provider="Digitonic\Infobip\InfobipServiceProvider"
Configuration
Edit .env with your Infobip credentials:
INFOBIP_USERNAME=your_username
INFOBIP_PASSWORD=your_password
INFOBIP_BASE_URL=https://api.infobip.com
First Use Case: Sending an SMS
use Digitonic\Infobip\Facades\Infobip;
Infobip::sms()->send([
'from' => 'YourBrand',
'to' => '441234567890',
'text' => 'Hello from Laravel!'
]);
config/infobip.php (API endpoints, default settings)app/Providers/InfobipServiceProvider.php (Service binding)vendor/digitonic/laravel-infobip/src/Facades/Infobip.php (Facade usage)SMS Messaging
// Basic SMS
Infobip::sms()->send(['to' => '1234567890', 'text' => 'Test']);
// Bulk SMS
Infobip::sms()->bulkSend([
'messages' => [
['to' => '1234567890', 'text' => 'Hello 1'],
['to' => '0987654321', 'text' => 'Hello 2']
]
]);
Email Campaigns
Infobip::email()->send([
'from' => 'noreply@example.com',
'to' => ['user@example.com'],
'subject' => 'Welcome',
'html' => '<p>Hello!</p>'
]);
Two-Way SMS (Callback Handling) Configure a webhook route:
Route::post('/infobip/webhook', [InfobipWebhookController::class, 'handle']);
Then implement InfobipWebhookController to parse incoming SMS replies.
Template-Based Messaging
Infobip::sms()->sendTemplate([
'from' => 'Brand',
'to' => '1234567890',
'text' => 'Welcome {{name}}!',
'vars' => ['name' => 'John']
]);
Queue Jobs for Async Sending Wrap Infobip calls in Laravel queues to avoid timeouts:
use Illuminate\Support\Facades\Queue;
Queue::push(function () {
Infobip::sms()->send(['to' => '1234567890', 'text' => 'Delayed message']);
});
Logging Responses Extend the service to log API responses:
Infobip::extend(function ($infobip) {
$infobip->afterSend(function ($response) {
\Log::info('Infobip Response', $response->toArray());
});
});
Fallback Mechanisms Combine with other providers (e.g., Twilio) for redundancy:
try {
Infobip::sms()->send(['to' => '1234567890', 'text' => 'Fallback test']);
} catch (\Exception $e) {
// Fallback to Twilio
}
Authentication Failures
.env credentials match Infobip’s application username/password (not user credentials).Rate Limits
try {
Infobip::sms()->send(...);
} catch (\Digitonic\Infobip\Exceptions\RateLimitExceeded $e) {
sleep(10); // Retry after delay
}
Webhook Delays
Infobip::sms()->send(['to' => '1234567890', 'text' => 'Test', 'idempotencyKey' => uniqid()]);
Character Limits
Infobip::setDebug(true); // Logs raw API requests/responses
Infobip::validate() to check request data before sending:
$validated = Infobip::validate([
'to' => '1234567890',
'text' => 'Test'
]);
Custom API Endpoints Override the base URL in config or dynamically:
Infobip::setBaseUrl('https://custom.infobip.com');
Add New Features Extend the facade to support unsupported endpoints (e.g., WhatsApp API):
Infobip::extend(function ($infobip) {
$infobip->whatsapp = new WhatsAppService($infobip->client);
});
Mocking for Tests Use Laravel’s mocking to test without hitting Infobip:
$this->mock(\Digitonic\Infobip\Infobip::class, function ($mock) {
$mock->shouldReceive('send')->andReturn(['success' => true]);
});
config/infobip.php:
'defaults' => [
'from' => 'YourBrandName',
],
'timeout' => 60, // seconds
How can I help you explore Laravel packages today?