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.
SmsClient), aligning with Laravel’s dependency injection and service container principles.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.SendSmsJob) for async processing.throttle middleware.from number vs. AWS SNS’s source), reducing vendor lock-in. Supports custom providers via the ProviderInterface.MockFacade).Provider class for custom logic.SendSmsJob (e.g., dead-letter queues) must be monitored. Risk mitigated by:
failed_jobs table and Laravel Horizon/Supervisor.composer.json (e.g., ^10.0).throttle:60 in middleware)?SmsSent event or add a cost field to the sms_logs table.HandleFailedJobs or use a third-party tool like Sentry.SmsClient::send() replaces direct API calls.SendSmsJob for async processing (requires database or redis queue driver).SmsSent/SmsFailed for side effects (e.g., updating user records).guzzlehttp/guzzle for HTTP requests).sms_logs table for tracking (migrations included). Customize via config/sms.php.HttpTests and MockFacade. Example:
$this->mock(SmsClient::class)->shouldReceive('send')->once();
ProviderInterface.composer require asanak/laravel-sms-client.php artisan vendor:publish --tag=sms-config.AWS_SNS_KEY, TWILIO_SID).SmsClient::send().SendSmsJob::dispatch()).SmsSent::class => [SmsLogger::class, 'handle']).SendSmsJob and providers.failed_jobs table and provider dashboards.handle() signature).sid vs. AWS’s messageId).SmsClient.sms_logs table with custom fields (e.g., user_id, template_id).SmsSent → increment user_sms_count).failed_jobs monitoring.SendSmsJob.composer update asanak/laravel-sms-client --with-dependencies
class CustomTwilioProvider extends Provider {
public function send($to, $message) {
// Updated API call
}
}
config/sms.php and use environment variables for secrets (e.g., .env):
AWS_SNS_KEY=${AWS_SNS_KEY}
TWILIO_FROM=+1234567890
sms_logs table:
SELECT * FROM sms_logs WHERE status = 'failed' ORDER BY created_at DESC;
// 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());
}
}
# Example Supervisor config
[program:sms-worker]
command=php artisan queue:work --queue=sms
numprocs=8
throttle middleware to prevent provider API abuse:
Route::middleware(['throttle:60,1'])->post('/send-otp', ...);
sms_logs entries:
How can I help you explore Laravel packages today?