avtonom/sms-devinotelecom-bundle
Install the Bundle
composer require avtonom/sms-devinotelecom-bundle:~1.1
Ensure compatibility with your Laravel version (note: this is a Symfony2 bundle; Laravel integration requires a bridge like symfony/console-bridge or symfony/http-foundation-bridge).
Configure Parameters
Add to .env (Laravel-style):
SMS_DEVINOTELECOM_LOGIN=your_login
SMS_DEVINOTELECOM_PASSWORD=your_password
SMS_DEVINOTELECOM_ORIGINATORS=["SenderName1","SenderName2"]
Map these to config/services.php (or equivalent) for dependency injection.
Register the Service Provider
In config/app.php, add:
'providers' => [
// ...
Avtonom\Sms\DevinoTelecomBundle\AvtonomSmsDevinoTelecomServiceProvider::class,
],
First Use Case: Send an SMS
Inject the SmsSender service and call:
$sender = app('sms.sender');
$result = $sender->send('+380641234567', 'Hello from Laravel!', 'YourBrand');
Sending SMS with Retry Logic
Wrap the sender in a retry mechanism (e.g., using Laravel’s retry helper or a custom decorator):
use Illuminate\Support\Facades\Retry;
Retry::times(3)->attempt(function () use ($sender) {
$sender->send($phone, $message, $originator);
});
Logging and Monitoring Use Laravel’s logging facade to capture SMS events:
try {
$result = $sender->send($phone, $message, $originator);
\Log::info('SMS sent', ['phone' => $phone, 'result' => $result]);
} catch (\Exception $e) {
\Log::error('SMS failed', ['error' => $e->getMessage()]);
}
Queueing SMS for Async Processing
Dispatch a job to a queue (e.g., sms:send):
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendSmsJob implements ShouldQueue {
use Queueable;
public $phone;
public $message;
public $originator;
public function handle() {
$sender = app('sms.sender');
$sender->send($this->phone, $this->message, $this->originator);
}
}
Balance and Session Management Fetch balance or session ID via the adapter:
$adapter = $sender->getAdapter();
$balance = $adapter->getBalance(); // Hypothetical; check bundle docs for exact method.
Laravel Service Container
Bind the Symfony service to Laravel’s container in AppServiceProvider:
public function register() {
$this->app->singleton('sms.sender', function ($app) {
return new \KPhoen\SmsSenderBundle\SmsSender(
$app['k_phoen_sms_sender.provider.devinotelecom']
);
});
}
Form Validation Use Laravel’s validation rules to sanitize phone numbers:
$validated = $request->validate([
'phone' => 'required|string|regex:/^\+?[0-9\s\-\(\)]{10,}$/',
'message' => 'required|string|max:160',
]);
Testing
Mock the SmsSender interface in PHPUnit:
$mockSender = Mockery::mock('overload:\KPhoen\SmsSenderBundle\SmsSender');
$mockSender->shouldReceive('send')->andReturn(['success' => true]);
$this->app->instance('sms.sender', $mockSender);
Symfony2 Dependency Mismatch
AppKernel.php with Laravel’s config/app.php and .env files.Monolog differently. Configure the logger via config/logging.php:
'channels' => [
'sms' => [
'driver' => 'single',
'path' => storage_path('logs/sms.log'),
],
],
HTTP Adapter Conflicts
CurlHttpAdapter (recommended) and BuzzHttpAdapter. For Laravel:
curl is enabled in php.ini or use Guzzle (install via composer require guzzlehttp/guzzle).Originator Validation
originators array in config must match Devino Telecom’s approved sender IDs. Test with a single value first:
SMS_DEVINOTELECOM_ORIGINATORS: ["YourBrand"]
Error Handling
AdapterException for API failures. Catch and log these explicitly:
try {
$sender->send($phone, $message);
} catch (\KPhoen\SmsSenderBundle\Exception\AdapterException $e) {
\Log::error('Devino Telecom API error', [
'code' => $e->getCode(),
'data' => $e->getData(),
]);
}
Character Encoding
$cleanMessage = preg_replace('/[^\x20-\x7E]/u', '', $message);
Enable Verbose Logging
Add to config/logging.php:
'sms' => [
'driver' => 'single',
'level' => 'debug',
'path' => storage_path('logs/sms.log'),
],
Inspect Raw API Responses
Extend the CurlHttpAdapter to dump responses:
// In a custom adapter class:
public function sendRequest($url, $data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
\Log::debug('Devino Telecom API Response', [
'url' => $url,
'data' => $data,
'response' => $response,
]);
return $response;
}
Test with Sandbox Credentials Request Devino Telecom’s sandbox environment credentials to avoid hitting rate limits during development.
Custom Adapter
Implement a Laravel-friendly adapter by extending Avtonom\Sms\DevinoTelecomBundle\Http\CurlHttpAdapter:
class LaravelCurlAdapter extends CurlHttpAdapter {
protected function getClient() {
return new \GuzzleHttp\Client(); // Or Laravel's HttpClient
}
}
Queueable SMS Service Create a Laravel job for async SMS:
class SendSmsJob implements ShouldQueue {
public $phone;
public $message;
public function handle() {
$sender = app('sms.sender');
$sender->send($this->phone, $this->message);
}
}
Rate Limiting
Integrate with Laravel’s throttle middleware or use spatie/rate-limiter to enforce Devino Telecom’s limits (e.g., 1 SMS/sec).
Webhook Listener Add a route to handle Devino Telecom’s delivery reports:
Route::post('/sms/webhook', [SmsWebhookController::class, 'handle']);
How can I help you explore Laravel packages today?