itpalert / web2sms-notification-channel
Web2sms Notification Channel for Laravel with full PHP 8.2+ type safety.
Installs: 57
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/itpalert/web2sms-notification-channel
Requires
- php: ^8.2
- illuminate/notifications: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- itpalert/web2sms: ^2.2
Requires (Dev)
- guzzlehttp/guzzle: ^7.2
- mockery/mockery: ^1.0
- orchestra/testbench: ^8.22|^9.5|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
This package makes it easy to send notifications using Web2sms with Laravel 8.0+.
Features
✅ Full PHP 8.0+ type safety
✅ Supports Laravel 8.x through 12.x
✅ SMS scheduling
✅ Unicode message support
✅ Status callbacks
✅ Custom sender IDs
✅ Client reference tracking
✅ 30+ comprehensive tests
Contents
Installation
You can install the package via composer:
composer require itpalert/web2sms-notification-channel
Configuration
Setting up the Web2sms service
Add the following environment variables to your .env:
WEB2SMS_KEY=8c78axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx WEB2SMS_SECRET=e9a689cfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx WEB2SMS_SMS_FROM=ALERT WEB2SMS_ACCOUNT_TYPE=prepaid
Add the following to your config/services.php:
'web2sms' => [ 'key' => env('WEB2SMS_KEY'), 'secret' => env('WEB2SMS_SECRET'), 'sms_from' => env('WEB2SMS_SMS_FROM', ''), 'account_type' => env('WEB2SMS_ACCOUNT_TYPE', 'prepaid'), ],
Usage
Now you can use the channel in your via() method inside the notification:
use ITPalert\Web2smsChannel\Messages\Web2smsMessage; use Illuminate\Notifications\Notification; class ProjectCreated extends Notification { public function via($notifiable) { return ['web2sms']; } public function toWeb2sms($notifiable) { return new Web2smsMessage('Your project has been created!'); } }
Routing notifications
Add the routeNotificationForWeb2sms method to your Notifiable model to specify which phone number to use:
public function routeNotificationForWeb2sms(Notification $notification): string { return $this->phone_number; }
Simple string message
public function toWeb2sms($notifiable): string { return 'Simple SMS message'; }
Available Message Methods
Basic Methods
public function toWeb2sms($notifiable): Web2smsMessage { return (new Web2smsMessage()) ->content('Your message content here') ->from('SENDER_ID'); }
Unicode Support
For messages containing special characters (Romanian diacritics, emojis, etc.):
public function toWeb2sms($notifiable): Web2smsMessage { return (new Web2smsMessage('Mesaj cu diacritice: ăîâșț')) ->unicode(); }
Client Reference
Track messages with a unique reference (max 40 characters):
public function toWeb2sms($notifiable): Web2smsMessage { return (new Web2smsMessage('Your message')) ->clientReference('order-' . $this->order->id); }
Status Callbacks
Get notified when message status changes:
public function toWeb2sms($notifiable): Web2smsMessage { return (new Web2smsMessage('Your message')) ->statusCallback(route('sms.status', $this->id)); }
Scheduled Messages
Send messages at a specific time:
public function toWeb2sms($notifiable): Web2smsMessage { return (new Web2smsMessage('Reminder message')) ->schedule('2024-12-25 10:00:00'); }
Displayed Message
Hide actual message content in dashboard (useful for sensitive data):
public function toWeb2sms($notifiable): Web2smsMessage { return (new Web2smsMessage('Your OTP is: 123456')) ->displayedMessage('OTP sent to customer'); }
Custom Client
Use a different Web2sms client for specific notifications:
public function toWeb2sms($notifiable): Web2smsMessage { $customClient = new \ITPalert\Web2sms\Client( 'different-key', 'different-secret' ); return (new Web2smsMessage('Your message')) ->usingClient($customClient); }
Complete Example
public function toWeb2sms($notifiable): Web2smsMessage { return (new Web2smsMessage()) ->content('Comanda #' . $this->order->id . ' a fost confirmată!') ->from('MAGAZIN') ->unicode() ->clientReference('order-' . $this->order->id) ->statusCallback(route('sms.status', $this->order->id)) ->displayedMessage('Order confirmation sent'); }
Testing
Run the tests with:
composer test
Run tests with coverage:
composer test-coverage
Run static analysis:
composer analyse
Check code style:
composer check-style
Fix code style:
composer format
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.