PHP code example of businessprocess / notify-service
1. Go to this page and download the library: Download businessprocess/notify-service library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
businessprocess / notify-service example snippets
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());
public function via($notifiable): array
{
return ['messenger'];
}
public function toMessenger($notifiable): string
{
return 'Text of body';
}
public function via($notifiable): array
{
return ['smart-sender'];
}
public function toSmartSender($notifiable): AbstractSender
{
return new BptPaymentsBot::task(
'ArrayOfParams'
);
}
$user = User::find(1);
Notification::send($user, new EmailNotification)
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);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.