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

Msg91 Php Laravel Package

kaydee123/msg91-php

PHP 8.0–8.5 client for MSG91 SMS & OTP: send single/bulk and template-based SMS, DLT-compliant messaging for India, send/verify/resend OTP (text/voice), fluent chainable API, strong error handling, framework-agnostic.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Microservice/Service Layer Fit: Ideal for decoupling SMS/OTP logic from business services (e.g., authentication, notifications). The fluent API design aligns with Laravel’s service-layer patterns, enabling clean separation of concerns.
  • Event-Driven Systems: Can integrate with Laravel’s event system (e.g., sending:otp, sms:delivered) via custom event listeners or observers.
  • Queue Integration: Supports Laravel’s queue system (e.g., sendSmsLater()) for async processing, reducing latency in user flows.
  • API Gateway: If using Laravel as an API gateway, the package’s thin abstraction layer allows direct proxying to MSG91’s API with minimal overhead.

Integration Feasibility

  • Laravel Ecosystem Compatibility:
    • Service Providers: Can be bootstrapped via Laravel’s ServiceProvider (e.g., Msg91ServiceProvider) to bind the client as a singleton.
    • Facades: Optional facade (Msg91::sms()->send()) for cleaner syntax in Blade/non-dependency-injected contexts.
    • Config Publishing: Supports publishing config files (e.g., msg91.php) for auth_key, base_url, and default routes (promotional/transactional).
    • Environment Variables: Aligns with Laravel’s .env conventions (e.g., MSG91_AUTH_KEY).
  • Database Integration:
    • OTP Storage: Can extend to store OTPs in Laravel’s database (e.g., otp_attempts table) for verification and retry logic.
    • SMS Logs: Supports logging sent SMS/OTPs to a sms_logs table for auditing (via Laravel’s query builder or Eloquent).
  • Testing:
    • Mocking: Easy to mock in PHPUnit using Laravel’s Mockery or createMock() for unit/feature tests.
    • Factories: Can create factories for Msg91Client in Laravel’s testing setup.

Technical Risk

  • DLT Compliance Complexity:
    • India-Specific: DLT template registration is mandatory for Indian numbers, requiring upfront coordination with MSG91 and TRAI. Risk of runtime errors if templates aren’t pre-registered.
    • Mitigation: Implement a pre-flight check in Laravel’s boot() to validate DLT templates for Indian routes.
  • Error Handling:
    • Custom Exceptions: The package’s ApiException and Msg91Exception can be extended to integrate with Laravel’s exception handler (e.g., logging to Sentry or custom error pages).
    • Retry Logic: MSG91’s API may throttle requests; implement exponential backoff in Laravel’s queue workers.
  • Deprecation Risk:
    • MSG91 API Changes: The package abstracts MSG91’s v5 API, but future API changes (e.g., v6) may require updates. Monitor MSG91’s changelog.
    • Mitigation: Use Laravel’s package:discover to auto-load the package and version-lock dependencies.

Key Questions

  1. Compliance Requirements:
    • Are DLT templates pre-registered for all Indian SMS/OTP use cases? If not, how will runtime failures be handled (e.g., fallback to non-DLT routes)?
  2. Performance:
    • Will SMS/OTP delivery be synchronous (blocking) or asynchronous (queued)? How will delays impact user experience?
  3. Cost Management:
    • How will SMS/OTP costs be monitored/alerted (e.g., Laravel Horizon for queue-based usage tracking)?
  4. Multi-Tenant Support:
    • If the app supports multiple tenants, how will MSG91 credentials/auth keys be scoped (e.g., per-tenant config or centralized)?
  5. Audit Logging:
    • Are SMS/OTP deliveries and failures being logged for compliance/auditing? If so, how will this integrate with Laravel’s logging system?

Integration Approach

Stack Fit

  • Laravel Core:
    • Service Container: Register Msg91Client as a singleton in AppServiceProvider with config-based auth key.
    • Facades (Optional): Create a Msg91 facade for Blade templates or non-injected contexts.
    • Config: Publish config/msg91.php for auth_key, base_url, default_route, and timeout.
  • Laravel Queues:
    • Wrap send() calls in dispatch() for async processing (e.g., SendSmsJob).
    • Use delay() for time-sensitive OTPs (e.g., 5-minute delay for verification).
  • Laravel Events:
    • Dispatch events for SMS/OTP lifecycle (e.g., SmsSent, OtpVerified) to trigger side effects (e.g., user notifications).
  • Laravel Validation:
    • Extend the package’s validation (e.g., Indian number format, DLT template presence) with Laravel’s FormRequest or Validator.

Migration Path

  1. Phase 1: Core Integration
    • Install the package via Composer.
    • Publish config and set MSG91_AUTH_KEY in .env.
    • Register the client in AppServiceProvider:
      public function boot()
      {
          $this->app->singleton(Msg91Client::class, function ($app) {
              return new Msg91Client(config('msg91.auth_key'));
          });
      }
      
  2. Phase 2: Async Processing
    • Create a SendSmsJob and update Msg91Client to dispatch jobs instead of sending directly.
    • Example:
      $client->sms()->template('TEMPLATE_ID')->numbers('919876543210')->dispatch();
      
  3. Phase 3: DLT Compliance
    • Add a middleware to validate DLT templates for Indian numbers before sending.
    • Example middleware:
      public function handle($request, Closure $next)
      {
          if ($request->routeIs('send.sms') && str_starts_with($request->mobile, '91')) {
              $this->validateDltTemplate($request->template_id);
          }
          return $next($request);
      }
      
  4. Phase 4: Observability
    • Log SMS/OTP deliveries to a sms_logs table using Laravel’s query builder.
    • Example:
      DB::table('sms_logs')->insert([
          'mobile' => $mobile,
          'status' => $response->status,
          'message_id' => $response->message_id,
          'created_at' => now(),
      ]);
      

Compatibility

  • PHP 8.0–8.5: Aligns with Laravel’s supported PHP versions (Laravel 10+).
  • Laravel Versions: Compatible with Laravel 8+ (no framework-specific dependencies).
  • Database: No hard dependencies; works with any database (MySQL, PostgreSQL, etc.) for logging.
  • Third-Party Packages:
    • Laravel Notifications: Can extend the Notification class to use Msg91Client for SMS channels.
    • Laravel Cashier: Integrate OTPs for payment verification.

Sequencing

  1. Pre-requisites:
    • Register DLT templates in MSG91 dashboard (if sending to India).
    • Set up MSG91 account and obtain auth_key.
  2. Development:
    • Start with synchronous calls in development.
    • Gradually introduce queues for production.
  3. Testing:
    • Mock Msg91Client in unit tests.
    • Test DLT validation for Indian numbers.
  4. Deployment:
    • Deploy config and credentials via Laravel Forge/Envoyer.
    • Monitor queue workers for SMS/OTP delivery.

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor kaydee123/msg91-php for updates and test compatibility with MSG91’s API changes.
    • Use Laravel’s composer.json conflict rules to prevent breaking changes.
  • Configuration Drift:
    • Centralize MSG91 credentials in Laravel’s .env or a secrets manager (e.g., AWS Secrets Manager).
    • Use Laravel’s config:cache to avoid runtime config reloads.
  • Deprecation:
    • Set up a deprecated tag in Laravel’s IDE helper to flag outdated Msg91Client usage.

Support

  • Error Handling:
    • Extend ApiException to include Laravel-specific context (e.g., user ID, request ID) for debugging.
    • Integrate with Laravel’s exception handler to log errors to Sentry or custom monitors.
  • User Feedback:
    • Surface MSG91’s error codes to end-users (e.g., "OTP not delivered due to invalid template").
    • Example:
      catch (ApiException $e) {
          return back()->withError("OTP Error: {$e->getResponse()['message']}");
      }
      
  • Support Channels:
    • Document
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity