NodeOffline.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Notifications;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Notifications\Messages\MailMessage;
  6. use Illuminate\Notifications\Notification;
  7. use NotificationChannels\Telegram\TelegramMessage;
  8. class NodeOffline extends Notification implements ShouldQueue
  9. {
  10. use Queueable;
  11. private $data;
  12. public function __construct($data)
  13. {
  14. $this->data = $data;
  15. }
  16. public function via($notifiable)
  17. {
  18. return sysConfig('node_offline_notification');
  19. }
  20. public function toMail($notifiable)
  21. {
  22. return (new MailMessage)
  23. ->subject(trans('notification.node_offline'))
  24. ->markdown('mail.simpleMarkdown', ['title' => trans('notification.node_offline_content'), 'content' => $this->markdownMessage(), 'url' => route('admin.node.index')]);
  25. }
  26. private function markdownMessage()
  27. {
  28. $content = '';
  29. foreach ($this->data as $node) {
  30. $content .= "- {$node['name']} {$node['host']}\r\n";
  31. }
  32. return $content;
  33. }
  34. public function toCustom($notifiable)
  35. {
  36. return [
  37. 'title' => trans('notification.node_offline'),
  38. 'content' => $this->markdownMessage(),
  39. ];
  40. }
  41. public function toBark($notifiable)
  42. {
  43. return [
  44. 'title' => trans('notification.node_offline'),
  45. 'content' => $this->stringMessage(),
  46. ];
  47. }
  48. private function stringMessage()
  49. {
  50. $content = '';
  51. foreach ($this->data as $node) {
  52. $content .= "{$node['name']} {$node['host']}| ";
  53. }
  54. return $content;
  55. }
  56. public function toTelegram($notifiable)
  57. {
  58. return TelegramMessage::create()
  59. ->token(sysConfig('telegram_token'))
  60. ->content($this->markdownMessage());
  61. }
  62. }