Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sms Devinotelecom Bundle Laravel Package

avtonom/sms-devinotelecom-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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).

  2. 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.

  3. Register the Service Provider In config/app.php, add:

    'providers' => [
        // ...
        Avtonom\Sms\DevinoTelecomBundle\AvtonomSmsDevinoTelecomServiceProvider::class,
    ],
    
  4. First Use Case: Send an SMS Inject the SmsSender service and call:

    $sender = app('sms.sender');
    $result = $sender->send('+380641234567', 'Hello from Laravel!', 'YourBrand');
    

Implementation Patterns

Workflows

  1. 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);
    });
    
  2. 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()]);
    }
    
  3. 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);
        }
    }
    
  4. 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.
    

Integration Tips

  • 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);
    

Gotchas and Tips

Pitfalls

  1. Symfony2 Dependency Mismatch

    • The bundle targets Symfony2, not Laravel. Key issues:
      • Service Container: Laravel’s container differs from Symfony’s. Use a bridge or abstract the service layer.
      • Configuration: Replace AppKernel.php with Laravel’s config/app.php and .env files.
      • Monolog Logger: Laravel uses Monolog differently. Configure the logger via config/logging.php:
        'channels' => [
            'sms' => [
                'driver' => 'single',
                'path' => storage_path('logs/sms.log'),
            ],
        ],
        
  2. HTTP Adapter Conflicts

    • The bundle provides CurlHttpAdapter (recommended) and BuzzHttpAdapter. For Laravel:
      • Ensure curl is enabled in php.ini or use Guzzle (install via composer require guzzlehttp/guzzle).
      • If using Guzzle, create a custom adapter wrapping Guzzle’s client.
  3. Originator Validation

    • The originators array in config must match Devino Telecom’s approved sender IDs. Test with a single value first:
      SMS_DEVINOTELECOM_ORIGINATORS: ["YourBrand"]
      
  4. Error Handling

    • The bundle throws 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(),
          ]);
      }
      
  5. Character Encoding

    • SMS messages are limited to 7-bit ASCII or GSM 03.38 encoding. Sanitize messages:
      $cleanMessage = preg_replace('/[^\x20-\x7E]/u', '', $message);
      

Debugging Tips

  1. Enable Verbose Logging Add to config/logging.php:

    'sms' => [
        'driver' => 'single',
        'level' => 'debug',
        'path' => storage_path('logs/sms.log'),
    ],
    
  2. 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;
    }
    
  3. Test with Sandbox Credentials Request Devino Telecom’s sandbox environment credentials to avoid hitting rate limits during development.

Extension Points

  1. 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
        }
    }
    
  2. 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);
        }
    }
    
  3. Rate Limiting Integrate with Laravel’s throttle middleware or use spatie/rate-limiter to enforce Devino Telecom’s limits (e.g., 1 SMS/sec).

  4. Webhook Listener Add a route to handle Devino Telecom’s delivery reports:

    Route::post('/sms/webhook', [SmsWebhookController::class, 'handle']);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware