deegitalbe / laravel-trustup-io-notifier
这是我创建的包:laravel-trustup-io-notifier
v1.5.1
2024-02-19 16:47 UTC
Requires
- php: ^8.0
- illuminate/contracts: ^8.0|^9.0|^10.0
- laravel/slack-notification-channel: ^2.4
- ramsey/uuid: ^4.3
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^6.0|^7.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5|^10.0
- spatie/laravel-ray: ^1.26
- dev-main
- v1.5.1
- v1.5.0
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- v0.3.2
- 0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-dependabot/github_actions/dependabot/fetch-metadata-1.4.0
- dev-releases/v1.2.0-support-slack-messages
- dev-dependabot/github_actions/ramsey/composer-install-2
- dev-dependabot/github_actions/actions/checkout-3.1.0
This package is auto-updated.
Last update: 2024-09-19 18:06:56 UTC
README
Trustup Pro Notifier
通过集中化的通知器实例轻松发送通知。支持通过自定义通知通道发送电子邮件(Postmark)、短信(Vonage/Nexmo)、邮政信件(Postbird)和推送(FCM)。只需一个应用名称和令牌即可使用所有这些通道。
安装
您可以通过composer安装此包
composer require deegitalbe/laravel-trustup-io-notifier
您可以使用以下命令发布和运行迁移
php artisan vendor:publish --tag="laravel-trustup-io-notifier-migrations"
php artisan migrate
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-trustup-io-notifier-config"
这是已发布配置文件的内容
return [ /** * Sets at which URL the notifier is accessible. * Default value: https://notifier.trustup.io */ 'url' => env('TPN_URL', 'https://notifier.trustup.io'), /** * App name (default, invoicing...). */ 'app' => env('TPN_APP_NAME', 'default'), /** * App key */ 'key' => env('TPN_APP_KEY') ];
用法
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; class DemoNotification extends Notification implements ShouldQueue { use Queueable; public $channels; /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['tpn_sms', 'tpn_email', 'tpn_letter', 'tpn_push', 'database']; } public function toTPNSMS($notifiable): array { return [ 'to' => '31657616867', 'text' => 'This is a test SMS' ]; } public function toTPNEmail($notifiable): array { return [ 'to' => 'florian.husquinet@deegital.be', 'html' => '<h1>Demo notification</h1><p>This is my email content...</p>', 'plain' => 'This is my email content...', 'subject' => 'Demo notification', 'headers' => [ 'X-Model-ID' => 1, 'X-Model-Type' => 'user' ] ]; } public function toTPNPush($notifiable): array { return [ 'to' => 'f0TAY_cMSpi2nNnakQ_B0w:APA91bFV1-2sblQS1h9mGn6I_aYJEZtww67fCJXN3Ir7V1179q7z_oHDLipQL1KAFs7meUyveVomzi2wLHTYuzXR7rDDnFiOBmCzGFEx-_aRszH0B2lIIelqzBjEjo5cL2t98bZc3B5g', 'name' => 'demo-notification', 'title' => 'Demo notification', 'body' => 'Lorem ipsum...', 'data' => [ 'type' => 'new-request', 'id' => '555' ] ]; } public function toTPNLetter($notifiable): array { return [ 'name' => 'demo-notification', 'pdf' => 'https://trustup-dev-billing.ams3.digitaloceanspaces.com/202202-2263%20(5).pdf' ]; } public function toArray($notifiable) { return [ 'channels' => $this->via($notifiable), 'to' => '31657616867', 'text' => 'This is a demo notification' ]; } }
发送通知时会发生什么
每个提供的通知通道将通过API调用通知器实例,并生成一个uuid,然后存储在notification_log_uuids
中。然后,您可以通过查询该uuid来查看您的通知在被发送到通知器后是如何表现的。
应从您的应用程序中排队发送通知,因为这是最佳做法。无论您在自己的应用程序中做什么,通知器都将接受通知并将其发送到自己的队列。处理之前可能存在几秒的延迟。