deegitalbe / laravel-trustup-io-notifier
This is my package laravel-trustup-io-notifier
Installs: 1 999
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 3
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-11-19 18:36:19 UTC
README
Trustup Pro Notifier
Easily send notifications through a centralized notifier instance. Supports emails (Postmak), sms (Vonage/Nexmo), postal letters (Postbird) and push (FCM) via custom notification channels that are easy to use. A single app name and token are enough to use all these channels.
Installation
You can install the package via composer:
composer require deegitalbe/laravel-trustup-io-notifier
You can publish and run the migrations with:
php artisan vendor:publish --tag="laravel-trustup-io-notifier-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="laravel-trustup-io-notifier-config"
This is the contents of the published config file:
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') ];
Usage
<?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' ]; } }
What happens when you send a notification
The channel will make the API call to the notifier instance for each channel provided with a uuid that is generated then stored in the notification_log_uuids
. You can then see how your notification behaved once it was send to the notifier by querying it using that uuid.
Notifications should be sent in queue from your app, as this is always the best possible use. Regardless of what you do in your own app, the notifier will accept the notification and send it to its own queue. There might be a delay of a few seconds before it is handled.