|
- <?php
-
- namespace App\Notifications;
-
- use App\Codes\QueueName;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Notifications\Notification;
- use Illuminate\Notifications\Slack\SlackMessage;
-
- class SlackNotification extends Notification implements ShouldQueue
- {
- use Queueable;
-
- protected $channel;
- protected $icon;
- protected $name;
- protected $message;
-
- /**
- * Create a new notification instance.
- */
- public function __construct($message)
- {
- // Slackに関数する情報はconfigに定義しておく
- $this->channel = config('slack.channel');
- $this->icon = config('slack.icon');
- $this->name = config('slack.sender_name');
- $this->message = $message;
- }
-
- /**
- * Get the notification's delivery channels.
- *
- * @return array<int, string>
- */
- public function via(object $notifiable): array
- {
- return ['slack'];
- }
-
- /**
- * Get the array representation of the notification.
- *
- * @return array<string, mixed>
- */
- public function toArray(object $notifiable): array
- {
- return [
- //
- ];
- }
-
- /**
- * Get the Slack representation of the notification.
- * @param mixed $notifiable
- * @return SlackMessage
- */
- public function toSlack(object $notifiable): SlackMessage
- {
- return (new SlackMessage)
- ->text($this->message);
- }
-
- /**
- * 各通知チャンネルで使用するキューを判断。
- *
- * @return array<string, string>
- */
- public function viaQueues(): array
- {
- return [
- 'slack' => QueueName::JOB->value,
- ];
- }
- }
|