deegitalbe / laravel-trustup-io-slack-notifications
Basic versioned php package.
Installs: 1 893
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.5
README
This package enhances laravel slack notifications, allowing to send direct messages.
Installation
Require package
composer require deegitalbe/laravel-trustup-io-slack-notifications
Env variables
SLACK_API_TOKEN=
Usage
Configure your models
use Illuminate\Database\Eloquent\Model; use Deegitalbe\LaravelTrustupIoSlackNotifications\Traits\Slack\SlackNotifiable; use Deegitalbe\LaravelTrustupIoSlackNotifications\Contracts\Slack\SlackNotifiableContract; use Illuminate\Notifications\Notification; class User extends Model implements SlackNotifiableContract { use SlackNotifiable; }
Configure your notification
Extending slack notification
use Illuminate\Notifications\Messages\SlackMessage; use Deegitalbe\LaravelTrustupIoSlackNotifications\SlackNotification; use Deegitalbe\LaravelTrustupIoSlackNotifications\Enum\SlackChannel; class OrderReceived extends SlackNotification { public function slackChannel($notifiable): string|SlackChannel { return SlackChannel::PRODUCTS; } public function slackMessage(SlackMessage $message, $notifiable): SlackMessage { return $message->content("A new order has been made."); } }
Implementing contract and using trait
use Illuminate\Notifications\Messages\SlackMessage; use Deegitalbe\LaravelTrustupIoSlackNotifications\Enum\SlackChannel; use Deegitalbe\LaravelTrustupIoSlackNotifications\Traits\Slack\IsSlackNotification; use Deegitalbe\LaravelTrustupIoSlackNotifications\Contracts\Slack\SlackNotificationContract; class OrderReceived extends Notification implements SlackNotificationContract { use IsSlackNotification; public function slackChannel($notifiable): string|SlackChannel { return $notifiable->getSlackId(); } public function slackMessage(SlackMessage $message, $notifiable): SlackMessage { return $message->content("A new order has been made."); } }