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 Gateway Bundle Laravel Package

andreybolonin/sms-gateway-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup for Laravel Integration

Since this is a Symfony bundle, direct Laravel integration requires a bridge. Use symfony/console and symfony/dependency-injection for compatibility. Start with:

  1. Install via Composer (Symfony-compatible):

    composer require andreybolonin/sms-gateway-bundle
    
  2. Bootstrap Symfony Components (Laravel Service Provider):

    // app/Providers/SmsGatewayServiceProvider.php
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
    use Symfony\Component\Config\FileLocator;
    
    class SmsGatewayServiceProvider extends ServiceProvider {
        public function register() {
            $container = new ContainerBuilder();
            $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config'));
            $loader->load('services.yaml'); // Define Symfony services here
            $this->app->singleton('sms.gateway', fn() => $container->get('sms.gateway'));
        }
    }
    
  3. First Use Case: Send an SMS via Twilio

    use Symfony\Component\DependencyInjection\ContainerInterface;
    
    $gateway = app('sms.gateway');
    $gateway->send('Twilio', [
        'to' => '+1234567890',
        'message' => 'Hello from Laravel!',
        'from' => '+1987654321'
    ]);
    

Implementation Patterns

1. Provider-Specific Configuration

Store credentials in Laravel’s .env and bind them to Symfony’s DI container:

# config/services.yaml
services:
    sms.gateway:
        class: AndreyBolonin\SmsGatewayBundle\Gateway\Gateway
        arguments:
            - '%env(TWILIO_SID)%'
            - '%env(TWILIO_TOKEN)%'
            - '%env(TWILIO_FROM)%'

2. Workflow: Sending SMS with Retries

Leverage Laravel’s retry helper for transient failures:

use Illuminate\Support\Facades\Retry;

Retry::times(3)->attempt(function () {
    $gateway->send('Twilio', ['to' => '+1234567890', 'message' => 'Retry test']);
});

3. Integration with Laravel Queues

Wrap the gateway in a job for async processing:

// app/Jobs/SendSmsJob.php
use AndreyBolonin\SmsGatewayBundle\Gateway\Gateway;

class SendSmsJob implements ShouldQueue {
    public function handle(Gateway $gateway) {
        $gateway->send('Nexmo', ['to' => '+1234567890', 'message' => 'Queued SMS']);
    }
}

4. Dynamic Provider Selection

Use Laravel’s config() to switch providers:

$provider = config('sms.default_provider');
$gateway->send($provider, ['to' => '+1234567890', 'message' => 'Dynamic provider']);

Gotchas and Tips

Pitfalls

  1. Symfony vs. Laravel DI:

    • Symfony’s ContainerBuilder expects YAML/XML config. Use symfony/dependency-injection for Laravel compatibility.
    • Fix: Pre-register services in SmsGatewayServiceProvider.
  2. Provider-Specific Quirks:

    • Twilio/Plivo: Require from number in every request.
    • SMSRU: Uses Cyrillic encoding; pass encoding: 'utf-8' explicitly.
    • Tropo: Needs account_sid and auth_token in the same format as Symfony’s TropoGateway.
  3. Rate Limits:

    • Providers like Clickatell throttle requests. Implement Laravel’s throttle middleware:
      Route::middleware(['throttle:60,1'])->post('/sms', [SmsController::class, 'send']);
      

Debugging

  • Enable Symfony Debug Mode:
    $container->setDebug(true); // In SmsGatewayServiceProvider
    
  • Log Provider Responses:
    $gateway->setLogger(app(\Psr\Log\LoggerInterface::class));
    

Extension Points

  1. Custom Providers: Extend AndreyBolonin\SmsGatewayBundle\Gateway\AbstractGateway and register via Symfony’s tags:

    services:
        app.custom_gateway:
            class: App\Gateway\CustomGateway
            tags: ['sms.gateway']
    
  2. Laravel Events: Trigger events after SMS sending:

    event(new SmsSent($provider, $response));
    
  3. Mocking for Tests: Use Laravel’s Mockery to stub the gateway:

    $mock = Mockery::mock(AndreyBolonin\SmsGatewayBundle\Gateway\Gateway::class);
    $mock->shouldReceive('send')->andReturn(['success' => true]);
    
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle