領収証発行サービス
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.7KB

  1. <?php
  2. namespace App\Notifications;
  3. use App\Codes\QueueName;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Notifications\Notification;
  7. use Illuminate\Notifications\Slack\SlackMessage;
  8. class SlackNotification extends Notification implements ShouldQueue
  9. {
  10. use Queueable;
  11. protected $channel;
  12. protected $icon;
  13. protected $name;
  14. protected $message;
  15. /**
  16. * Create a new notification instance.
  17. */
  18. public function __construct($message)
  19. {
  20. // Slackに関数する情報はconfigに定義しておく
  21. $this->channel = config('slack.channel');
  22. $this->icon = config('slack.icon');
  23. $this->name = config('slack.sender_name');
  24. $this->message = $message;
  25. }
  26. /**
  27. * Get the notification's delivery channels.
  28. *
  29. * @return array<int, string>
  30. */
  31. public function via(object $notifiable): array
  32. {
  33. return ['slack'];
  34. }
  35. /**
  36. * Get the array representation of the notification.
  37. *
  38. * @return array<string, mixed>
  39. */
  40. public function toArray(object $notifiable): array
  41. {
  42. return [
  43. //
  44. ];
  45. }
  46. /**
  47. * Get the Slack representation of the notification.
  48. * @param mixed $notifiable
  49. * @return SlackMessage
  50. */
  51. public function toSlack(object $notifiable): SlackMessage
  52. {
  53. return (new SlackMessage)
  54. ->text($this->message);
  55. }
  56. /**
  57. * 各通知チャンネルで使用するキューを判断。
  58. *
  59. * @return array<string, string>
  60. */
  61. public function viaQueues(): array
  62. {
  63. return [
  64. 'slack' => QueueName::JOB->value,
  65. ];
  66. }
  67. }