businessprocess/notify-service
最新稳定版本:v2.0.4
Composer 安装命令:
composer require businessprocess/notify-service
包简介
Package for notification channels
README 文档
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
| Option | Description | Default value |
|---|---|---|
| url | API url (required) | null |
| login | Login (required) | null |
| password | Password (required) | null |
| profileUuid | Uuid of delivery profile | null |
Params Heroku/BptPaymentsBot/SmartSender
| Option | Description | Default value |
|---|---|---|
| profileUuid | Uuid of delivery profile (required) | null |
| langCode | Notify template locale (required) | null |
| emitter | Group by string key | null |
| destination | Recipient channel keys (required) | null,object |
| data | Template data (required if no text) | null,object |
| text | Message text (required if no data) | null |
| options | Options | null,object |
| key | Group by key | null |
| timeToDelivery | Time to delivery | null |
public function via($notifiable): array { return ['messenger']; } public function toMessenger($notifiable): string { return 'Text of body'; }
Available Options
| Option | Description | Default value |
|---|---|---|
| authentication | Your API key (required) | null |
| url | API url (required) | null |
| project_id | Project iD (required) | null |
| messenger | List of messengers (required) | viber |
| sendAll | Send to all messenger in list | false |
| callback_url | Callback url to response from messenger | null |
| user_phone | User phone | null |
public function via($notifiable): array { return ['smart-sender']; } public function toSmartSender($notifiable): AbstractSender { return new BptPaymentsBot::task( 'ArrayOfParams' ); }
Available Options
| Option | Description | Default value |
|---|---|---|
| url | API url (required) | null |
Params Heroku/BptPaymentsBot/SmartSender
| Option | Description | Default value |
|---|---|---|
| requestID | Your request ID (required) | null |
| date | Date by format Y-m-d H:i:s (required) | null |
| type | Request type (required) | null |
| notes | Comment (required) | null |
| user | User name (required) | null |
| author | Author name (required) | null |
| amount | Amount (required) | null |
| applyUrl | Callback approve url (required) | null |
| declineUrl | Callback cancel url (required) | null |
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);
统计信息
- 总下载量: 5.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-19