carropublic / notifications
A collections of notification channels and senders
Installs: 24 421
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 1
Open Issues: 0
Requires
- illuminate/collections: ~9|~10|~11
- illuminate/events: ~9|~10|~11
- illuminate/notifications: ~9|~10|~11
- illuminate/support: ~9|~10|~11
- linecorp/line-bot-sdk: ^4.3|^7.3
- twilio/sdk: ^6|^7
This package is auto-updated.
Last update: 2024-11-19 03:26:56 UTC
README
Installation
Via Composer
$ composer require carropublic/notifications
Run the following vendor publish to publish Twillo config.
php artisan vendor:publish --provider="CarroPublic\Notifications\NotificationServiceProvider"
Usage
LaravelNotification
The following is the example usage of the package with Laravel's Notification.
Create Notification Class
class ExampleNotification extends Notification
{
// Which channel this notification should be sent to
public function via($notifiable)
{
return [ SMSChannel::class, WhatsAppChannel::class ];
}
// Notification payload (content) will be sent
public function toSMS($notifiable)
{
return new LaravelTwilioMessage("Message Content");
}
// Notification payload (content) will be sent
public function toWhatsApp($notifiable)
{
return new LaravelTwilioMessage("Message Content");
}
}
Create Notifiable Class
class Contact extends Model {
use Notifiable;
// Phone number to receive
public function routeNotificationForSms()
{
return $this->phone;
}
// Phone number to receive
public function routeNotificationForWhatsapp()
{
return $this->phone;
}
}
Sending Notification from Notifiable Instance
$contact->notify(new ExampleNotification());
Sending Notification from Anonymous Notifiable Instance
Notification::route('sms')->notify(new ExampleNotification());
Sandbox Mode
How to enable SandBox Mode
- Register Closure to return if testing is enabled
\CarroPublic\Notifications\Senders\Sender::registerSandboxValidator
Example:
Sender::registerSandboxValidator(function () {
return !is_production();
});
- Otherwise, use
NOTIFICATION_SANDBOX_ENABLE
to determine if running in sandbox mode. Defaultfalse
⛔️ Notes: If the closure is registered, the env will be ignored
How to bypass sandbox validator
- Register Closure to return if sandbox is enabled
\CarroPublic\Notifications\Senders\Sender::registerValidForSandbox
$to: the recipient the message will be sent to $type: the sender class
- LineSender
- TelerivetSender
- TwilioSender
- MailChannel (Since there is not MailSender, the MailChannel will be used instead)
LaravelTwilioSender::registerValidPhoneForSandbox(function ($to, $type) {
switch ($type) {
case LineSender::class:
return true;
case TwilioSender::class:
return false;
}
}
Change log
Please see the changelog for more information on what has changed recently.
Security
If you discover any security related issues, please email author email instead of using the issue tracker.
Credits
License
Please see the license file for more information.