TicketClosed.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 TicketClosed extends Notification implements ShouldQueue
  9. {
  10. use Queueable;
  11. private $ticketId;
  12. private $title;
  13. private $url;
  14. private $reason;
  15. private $is_user;
  16. public function __construct($ticketId, $title, $url, $reason, $is_user = false)
  17. {
  18. $this->ticketId = $ticketId;
  19. $this->title = $title;
  20. $this->url = $url;
  21. $this->reason = $reason;
  22. $this->is_user = $is_user;
  23. }
  24. public function via($notifiable)
  25. {
  26. return $this->is_user ? ['mail'] : sysConfig('ticket_closed_notification');
  27. }
  28. public function toMail($notifiable)
  29. {
  30. return (new MailMessage)
  31. ->subject(trans('notification.close_ticket', ['id' => $this->ticketId, 'title' => $this->title]))
  32. ->line($this->reason)
  33. ->action(trans('notification.view_ticket'), $this->url)
  34. ->line(__('If your problem has not been solved, Feel free to open other one.'));
  35. }
  36. public function toCustom($notifiable)
  37. {
  38. return [
  39. 'title' => trans('notification.close_ticket', ['id' => $this->ticketId, 'title' => $this->title]),
  40. 'content' => $this->reason,
  41. ];
  42. }
  43. public function toTelegram($notifiable)
  44. {
  45. return TelegramMessage::create()
  46. ->token(sysConfig('telegram_token'))
  47. ->content($this->reason);
  48. }
  49. }