businessprocess / notify-service
Package for notification channels
Installs: 4 379
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- businessprocess/oidc-auth: ^1.0
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- laravel/framework: ^9.0
- laravel/pint: ^1.1
- phpunit/phpunit: ^9.3.3
README
Notification messenger channel to Laravel FrameWork v6.0 and above.
Installation
The recommended way to install channel is through Composer.
composer require businessprocess/notify-service
Usage
Notify::getDeliveryProfiles() - Get all delivery profiles Notify::notifications() - get all notification
namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; class MyNotification extends Notification implements ShouldQueue { public function via($notifiable): array { return ['notify']; } public function toNotify($notifiable) { $notice = \NotificationChannels\Models\NotifyService\Notice::create('profileUuid'); $notice->setLangCode(app()->getLocale()) ->setTimeToDelivery(now()->addHour()) ->setText('Welcome to hell') ->options() ->email( 'Hello email', 'From admin' ); $notice->destination() ->email($notifiable->email) ->viber($notifiable->phone); //add file to notice $notice->setFile(storage_path('./random.jpg')) $notice->responseCallback(function (?array $response){ // can be processed response from notify service if(! is_null($response)){ echo data_get($response, 'id'); } }) return $notice; } }
// Notice object can be obtained from the container with the addition of the profileUuid from the configuration public function toNotify($notifiable, \NotificationChannels\Models\NotifyService\Notice $notice) { return $notice->fill('ArrayOfParams'); } }
//call $user->notify(new MyNotification()); //or multiply users Notification::send($users, new MyNotification());
Available Options
Params Heroku/BptPaymentsBot/SmartSender
public function via($notifiable): array { return ['messenger']; } public function toMessenger($notifiable): string { return 'Text of body'; }
Available Options
public function via($notifiable): array { return ['smart-sender']; } public function toSmartSender($notifiable): AbstractSender { return new BptPaymentsBot::task( 'ArrayOfParams' ); }
Available Options
Params Heroku/BptPaymentsBot/SmartSender
Usage Laravel
$user = User::find(1); Notification::send($user, new EmailNotification)
Usage YII2
[ 'modules' => [ 'notifications' => [ 'class' => 'NotificationChannels\yii\Module', 'channels' => [ 'notify' => [ 'class' => 'NotificationChannels\yii\Channels\NotifyChannel', 'url' => $params['notifyService']['url'], 'login' => $params['notifyService']['login'], 'password' => $params['notifyService']['password'], ], ], ], ], ], ]
namespace app\notifications; use NotificationChannels\yii\Notification; use NotificationChannels\Models\NotifyService\Notice; class EmailNotification extends Notification { public function via($notifiable): array { return ['notify']; } public function toNotify($notifiable) { return Notice::create( 'ArrayOfParams' ); } }
$user = User::findOne(1); EmailNotification::create()->sendTo($user); // (new EmailNotification())->sendTo($user);