| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Notifications;
- use App\Models\TicketReply;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Notifications\Messages\MailMessage;
- use Illuminate\Notifications\Notification;
- use NotificationChannels\Telegram\TelegramMessage;
- class TicketReplied extends Notification implements ShouldQueue
- {
- use Queueable;
- private TicketReply $reply;
- private string $url;
- private bool $is_user;
- public function __construct(TicketReply $reply, string $url, bool $is_user = false)
- {
- $this->reply = $reply;
- $this->url = $url;
- $this->is_user = $is_user;
- }
- public function via($notifiable)
- {
- return $this->is_user ? ['mail'] : sysConfig('ticket_replied_notification');
- }
- public function toMail($notifiable): MailMessage
- {
- return (new MailMessage)
- ->subject(trans('notification.reply_ticket', ['title' => $this->reply->ticket->title]))
- ->line(trans('notification.ticket_content'))
- ->line(strip_tags($this->reply->content))
- ->action(trans('notification.view_ticket'), $this->url);
- }
- public function toCustom($notifiable): array
- {
- return [
- 'title' => trans('notification.reply_ticket', ['title' => $this->reply->ticket->title]),
- 'content' => trans('notification.ticket_content').strip_tags($this->reply->content),
- ];
- }
- public function toTelegram($notifiable): TelegramMessage
- {
- return TelegramMessage::create()
- ->token(sysConfig('telegram_token'))
- ->content($this->markdownMessage($this->reply))
- ->button(trans('notification.view_ticket'), $this->url);
- }
- private function markdownMessage(TicketReply $reply): string
- {
- return "📮工单回复提醒 #{$reply->ticket->id}\n———————————————\n主题:\n`{$reply->ticket->title}`\n内容:\n`$reply->content`";
- }
- public function toBark($notifiable): array
- {
- return [
- 'title' => trans('notification.reply_ticket', ['title' => $this->reply->ticket->title]),
- 'content' => trans('notification.ticket_content').strip_tags($this->reply->content),
- 'group' => '工单',
- 'icon' => asset('assets/images/notification/ticket.png'),
- 'url' => $this->url,
- ];
- }
- }
|