kaydee123/msg91-laravel
Laravel integration for MSG91 SMS and OTP services. Send single/bulk SMS, template-based messages, OTP send/verify/resend (text/voice), and DLT-ready India compliance. Includes auto-discovery service provider, facade, helpers, and publishable config.
Installation:
composer require kaydee123/msg91-laravel
The package auto-registers via Laravel’s auto-discovery.
Configuration: Publish the config file:
php artisan vendor:publish --tag=msg91-config
Update .env with your MSG91 credentials:
MSG91_AUTH_KEY=your_auth_key
First Use Case: Send a basic SMS via the facade:
use Kaydee123\Msg91\Facades\Msg91;
Msg91::sendSms('919876543210', 'Hello from Laravel!');
Kaydee123\Msg91\Facades\Msg91 (for quick usage).config/msg91.php (for customization).src/Helpers for utility functions (if any).Sending SMS:
Msg91::sendSms('919876543210', 'Your OTP is 123456');
Msg91::sendBulkSms(['919876543210', '919876543211'], 'Hello all!');
Msg91::sendTemplateSms('919876543210', 'OTP_TEMPLATE_ID', ['otp' => '123456']);
OTP Management:
$otp = Msg91::sendOtp('919876543210', 'OTP_TEMPLATE_ID', ['otp' => '123456']);
$isValid = Msg91::verifyOtp('919876543210', '123456', $otp->id);
Msg91::resendOtp($otp->id);
Error Handling:
Wrap calls in try-catch to handle exceptions (e.g., Msg91Exception):
try {
Msg91::sendSms('919876543210', 'Test');
} catch (\Kaydee123\Msg91\Exceptions\Msg91Exception $e) {
Log::error('MSG91 Error: ' . $e->getMessage());
}
Msg91::queueSms('919876543210', 'Hello', 'default');
.env (MSG91_DEBUG=true) for API response logging.$this->mock(Msg91::class)->shouldReceive('sendSms')->andReturn(true);
Authentication Errors:
401 Unauthorized if MSG91_AUTH_KEY is invalid or expired..env.Rate Limits:
429 Too Many Requests by:
Msg91::retry() helper if available.DLT Compliance (India):
sendTemplateSms().Timeouts:
MSG91_TIMEOUT). Increase if API responses are slow:
MSG91_TIMEOUT=60
Enable Debug Mode:
MSG91_DEBUG=true
Logs API requests/responses to storage/logs/msg91.log.
Check Response Codes:
MSG91 returns HTTP codes (e.g., 200 for success, 400 for invalid params). Refer to MSG91 API Docs for specifics.
Custom Templates: Extend the package by adding template logic in a service class:
class CustomMsg91Service extends \Kaydee123\Msg91\Msg91Service {
public function sendCustomTemplate($mobile, $templateData) {
// Custom logic
}
}
Event Listeners: Listen for SMS/OTP events (if the package emits them):
// config/listeners.php
'Kaydee123\Msg91\Events\SmsSent' => [
\App\Listeners\LogSmsSent::class,
],
Override Config:
Extend the published config file (config/msg91.php) to add custom settings:
'custom' => [
'prefix' => '+91',
],
sendBulkSms() for cost efficiency when sending to multiple numbers.How can I help you explore Laravel packages today?