frolax / ultimate-sms-notification-channel
Laravel notification channel for UltimateSms
Requires
- php: ^8.0
- illuminate/notifications: ^8.0|^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0|^10.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.0|^10.4|^11.5
README
This package provides a Laravel notification channel for UltimateSms.
Installation
You can install the package via composer:
composer require frolax/ultimate-sms-notification-channel
The package will automatically register itself.
You can publish the config file with:
php artisan vendor:publish --provider="Frolax\UltimateSms\UltimateSmsServiceProvider" --tag="config"
This will create a config/ultimate-sms.php
file in your config directory.
Configuration
Add the following to your .env
file:
ULTIMATE_SMS_API_KEY=your-api-key
ULTIMATE_SMS_BASE_URL=https://sms.test/api/v3
ULTIMATE_SMS_DEFAULT_SENDER_ID=YourName
Usage
Using the Facade
You can use the UltimateSms Facade to send messages directly:
use Frolax\UltimateSms\Facades\UltimateSms; // Send to a single recipient UltimateSms::send( '31612345678', 'Your message here', 'OptionalSenderId' ); // Send to multiple recipients UltimateSms::sendToMany( ['31612345678', '880172145789'], 'Your message here', 'OptionalSenderId' ); // Schedule a message UltimateSms::send( '31612345678', 'Your message here', 'OptionalSenderId', '2021-12-20 07:00' );
Using Notifications
To use the UltimateSms channel in your notification, add the toUltimateSms
method to your notification class:
use Frolax\UltimateSms\Messages\UltimateSmsMessage; use Illuminate\Notifications\Notification; class YourNotification extends Notification { public function via($notifiable) { return ['ultimate-sms']; } public function toUltimateSms($notifiable) { return UltimateSmsMessage::create( $notifiable->phone_number, // The recipient's phone number 'Your message here', // The message content 'OptionalSenderId' // Optional sender ID ); } }
Multiple Recipients
To send a message to multiple recipients, you can provide a comma-separated list of phone numbers:
public function toUltimateSms($notifiable) { return UltimateSmsMessage::create( '31612345678,880172145789', // Multiple recipients 'Your message here', 'OptionalSenderId' ); }
Scheduled Messages
To schedule a message for later delivery, provide a schedule time in the format 'YYYY-MM-DD HH:mm':
public function toUltimateSms($notifiable) { return UltimateSmsMessage::create( $notifiable->phone_number, 'Your message here', 'OptionalSenderId', '2021-12-20 07:00' // Schedule time ); }
Response Format
The API will return a response in the following format:
{ "status": "success", "data": "sms reports with all details" }
If the request fails, it will return:
{ "status": "error", "message": "A human-readable description of the error" }
License
The MIT License (MIT). Please see License File for more information.