## Getting Started
Install the package via Composer:
```bash
composer require vendor/sms-package
Publish the configuration file (if available) to customize API credentials:
php artisan vendor:publish --provider="Vendor\SmsPackage\SmsPackageServiceProvider"
Register the SMS service in config/services.php with your API credentials (e.g., SMS_API_KEY, SMS_API_SECRET).
First Use Case: Send a basic SMS via the facade or service container:
use Vendor\SmsPackage\Facades\Sms;
// Send a single SMS
Sms::send('+1234567890', 'Hello from Laravel!');
Check the documentation for API endpoint specifics (e.g., rate limits, character limits).
Configuration:
Store API credentials in .env (e.g., SMS_API_KEY=your_key_here).
Override defaults in config/sms.php if needed.
Sending SMS:
Sms::send($phone, $message) for simplicity.AppServiceProvider for dependency injection:
$this->app->bind('sms', function ($app) {
return new \Vendor\SmsPackage\SmsService($app['config']['sms']);
});
use Vendor\SmsPackage\Jobs\SendSms;
SendSms::dispatch('+1234567890', 'Your OTP is 1234')->delay(now()->addSeconds(5));
Response Handling: Check the response object for status:
$response = Sms::send($phone, $message);
if ($response->success()) {
// Handle success
} else {
log::error('SMS failed: ' . $response->getError());
}
vendor/sms-package/helpers if available).\Log::channel('sms')->info('SMS sent to ' . $phone, ['message' => $message]);
$this->partialMock(Sms::class, function ($mock) {
$mock->shouldReceive('send')->andReturn(new \Vendor\SmsPackage\Response(true));
});
API Rate Limits:
The package does not enforce rate limits by default. Monitor your API usage to avoid throttling.
Workaround: Implement a throttle middleware or use a queue with delay.
Character Limits:
SMS messages are typically limited to 160 characters (or 70 for Unicode). Longer messages may be split or fail silently.
Tip: Use Str::limit($message, 150) to enforce safe lengths.
No Retry Mechanism: Failed SMS sends are not retried automatically. Implement exponential backoff in your job if reliability is critical.
No Multi-Part SMS Support: Only single-part SMS is supported in v1.0. Plan for message truncation if sending longer texts.
SMS_DEBUG=true in .env to log raw API responses.200 (Success)400 (Bad Request, e.g., invalid phone)429 (Too Many Requests)500 (Server Error)Custom Responses:
Extend the Response class to add domain-specific logic:
class CustomResponse extends \Vendor\SmsPackage\Response {
public function isDeliveryReport() {
return $this->data['status'] === 'DELIVERED';
}
}
Bind your custom class in AppServiceProvider.
Add New Features:
The package is modular. Fork and extend the SmsService class to support:
generateOtp() method.Hello {name}).registerWebhook method for delivery notifications.Support for Other APIs:
The package may abstract the underlying SMS provider. Check the source for SmsService::send() to see how to add support for Twilio, AWS SNS, etc.
+1234567890). Normalize phone numbers before sending:
$phone = '+'. ltrim($rawPhone, '+');
.env variables like SMS_API_KEY_STAGING and switch them via:
config(['sms.api_key' => env('SMS_API_KEY_' . app()->environment())]);
NO_UPDATE_NEEDED would **not** apply here due to the new v1.0 release introducing core functionality. The above is the updated assessment.
How can I help you explore Laravel packages today?