businessprocess/notify-service

Package for notification channels

v2.0.2 2025-01-06 14:30 UTC

README

PHP 8.x Laravel 8.x Yii 2.x Latest Stable Version Release date Release Version Total Downloads Pull requests Software License Stars

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);