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

Laravel Sms Client Laravel Package

asanak/laravel-sms-client

Laravel package for sending SMS via Asanak API. Supports simple send, P2P messages, OTP templates, and message status reports. Includes config publishing, .env credentials, optional logging, and auto-registered service provider and facade.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Modularity: The package follows Laravel’s service provider pattern, making it easy to integrate into existing Laravel applications without disrupting core architecture. It abstracts SMS provider APIs (e.g., Twilio, AWS SNS, or custom gateways) behind a unified facade (SmsClient), aligning with Laravel’s dependency injection and service container principles.
  • Event-Driven Reporting: Leverages Laravel’s event system (SmsSent, SmsFailed) for async processing (e.g., logging, retries, or analytics), which fits well with event-driven architectures. This reduces coupling between SMS logic and business workflows.
  • Configuration Flexibility: Supports dynamic provider switching via config files, which is ideal for multi-tenant or environment-specific deployments (e.g., dev/staging/prod gateways).

Integration Feasibility

  • Low Friction for Laravel Apps: Designed specifically for Laravel, with built-in support for:
    • Queueable jobs (SendSmsJob) for async processing.
    • Rate limiting via Laravel’s throttle middleware.
    • Eloquent model observers for SMS-triggered actions (e.g., sending OTPs on user creation).
  • Provider Agnosticism: Abstracts provider-specific quirks (e.g., Twilio’s from number vs. AWS SNS’s source), reducing vendor lock-in. Supports custom providers via the ProviderInterface.
  • Testing: Includes mockable facades and service providers, easing unit/integration testing (e.g., using Laravel’s MockFacade).

Technical Risk

  • Provider-Specific Edge Cases: Undocumented quirks in unsupported providers (e.g., SMS length limits, encoding) may require custom provider implementations. Mitigate by:
    • Testing with the target provider’s sandbox environment pre-launch.
    • Extending the base Provider class for custom logic.
  • Async Reliability: If using queues, failures in SendSmsJob (e.g., dead-letter queues) must be monitored. Risk mitigated by:
    • Configuring failed_jobs table and Laravel Horizon/Supervisor.
    • Implementing retry logic with exponential backoff in the job.
  • Deprecation Risk: New Laravel versions (e.g., 11.x) may introduce breaking changes. Risk mitigated by:
    • Pinning Laravel version in composer.json (e.g., ^10.0).
    • Monitoring the package’s GitHub for updates.

Key Questions

  1. Provider Support: Does the target SMS provider (e.g., Clickatell, MessageBird) have a documented REST API? If not, will a custom provider adapter be needed?
  2. Rate Limits: What are the provider’s rate limits (e.g., 1 SMS/sec)? How will throttling be configured in Laravel (e.g., throttle:60 in middleware)?
  3. Cost Tracking: How will SMS costs be logged/attributed (e.g., per-user, per-feature)? Extend the SmsSent event or add a cost field to the sms_logs table.
  4. Compliance: Are there regional SMS regulations (e.g., TCPA for the US)? Will opt-out handling require custom logic (e.g., storing unsubscribe codes)?
  5. Monitoring: How will SMS delivery failures be alerted (e.g., Slack, PagerDuty)? Integrate with Laravel’s HandleFailedJobs or use a third-party tool like Sentry.

Integration Approach

Stack Fit

  • Laravel Core: Seamless integration with:
    • Facades: SmsClient::send() replaces direct API calls.
    • Queues: SendSmsJob for async processing (requires database or redis queue driver).
    • Events: SmsSent/SmsFailed for side effects (e.g., updating user records).
  • PHP Extensions: No additional extensions required beyond Laravel’s defaults (e.g., guzzlehttp/guzzle for HTTP requests).
  • Database: Optional sms_logs table for tracking (migrations included). Customize via config/sms.php.
  • Testing: Works with Laravel’s HttpTests and MockFacade. Example:
    $this->mock(SmsClient::class)->shouldReceive('send')->once();
    

Migration Path

  1. Discovery Phase (1–2 days):
    • Audit existing SMS logic (e.g., direct API calls, cron jobs).
    • Identify providers and map their APIs to the package’s ProviderInterface.
  2. Setup (1 day):
    • Install package: composer require asanak/laravel-sms-client.
    • Publish config: php artisan vendor:publish --tag=sms-config.
    • Configure provider (e.g., AWS_SNS_KEY, TWILIO_SID).
  3. Integration (2–3 days):
    • Replace direct API calls with SmsClient::send().
    • Migrate sync calls to queues (e.g., SendSmsJob::dispatch()).
    • Add event listeners for side effects (e.g., SmsSent::class => [SmsLogger::class, 'handle']).
  4. Testing (2–3 days):
    • Unit test SendSmsJob and providers.
    • Integration test with provider sandbox (e.g., Twilio’s trial number).
    • Load test with expected peak SMS volume (e.g., 100 SMS/min).
  5. Deployment (1 day):
    • Roll out in stages (e.g., non-critical features first).
    • Monitor failed_jobs table and provider dashboards.

Compatibility

  • Laravel Versions: Tested with Laravel 10.x. For Laravel 11.x, check for breaking changes in:
    • Service provider boot methods.
    • Queue job handling (e.g., handle() signature).
  • PHP Versions: Requires PHP 8.1+. Upgrade if using PHP 8.0.
  • Provider APIs: Validate provider APIs match the package’s expected response formats (e.g., Twilio’s sid vs. AWS’s messageId).

Sequencing

  1. Phase 1: Core SMS Replacement
    • Replace all direct SMS API calls with SmsClient.
    • Implement queue-based sending for high-volume use cases.
  2. Phase 2: Reporting & Analytics
    • Extend sms_logs table with custom fields (e.g., user_id, template_id).
    • Add event listeners for analytics (e.g., SmsSent → increment user_sms_count).
  3. Phase 3: Error Handling
    • Configure failed_jobs monitoring.
    • Implement retries with exponential backoff in SendSmsJob.
  4. Phase 4: Scaling
    • Optimize queue workers (e.g., Laravel Horizon for Redis).
    • Add rate limiting middleware for API endpoints triggering SMS.

Operational Impact

Maintenance

  • Package Updates: Monitor for Laravel version compatibility. Update via:
    composer update asanak/laravel-sms-client --with-dependencies
    
  • Provider Changes: If the SMS provider updates its API (e.g., Twilio’s v2023-07-01), extend the provider class:
    class CustomTwilioProvider extends Provider {
        public function send($to, $message) {
            // Updated API call
        }
    }
    
  • Configuration Drift: Centralize SMS settings in config/sms.php and use environment variables for secrets (e.g., .env):
    AWS_SNS_KEY=${AWS_SNS_KEY}
    TWILIO_FROM=+1234567890
    

Support

  • Debugging: Leverage Laravel’s logging and the sms_logs table:
    SELECT * FROM sms_logs WHERE status = 'failed' ORDER BY created_at DESC;
    
  • Provider-Specific Issues: Isolate provider logic in custom classes to avoid contaminating the core package. Example:
    // app/Providers/TwilioServiceProvider.php
    public function send($to, $message) {
        try {
            // Twilio-specific logic
        } catch (\Exception $e) {
            Log::error("Twilio failed: " . $e->getMessage());
            throw new ProviderException($e->getMessage());
        }
    }
    
  • User Support: Document SMS failure flows (e.g., "If you don’t receive an OTP, check your spam folder or contact support").

Scaling

  • Queue Workers: Scale horizontally with Laravel Horizon or Supervisor:
    # Example Supervisor config
    [program:sms-worker]
    command=php artisan queue:work --queue=sms
    numprocs=8
    
  • Rate Limiting: Use Laravel’s throttle middleware to prevent provider API abuse:
    Route::middleware(['throttle:60,1'])->post('/send-otp', ...);
    
  • Database Load: For high-volume logging, archive old sms_logs entries:
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.
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
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope