-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ReminderTriggered.php
96 lines (84 loc) · 2.49 KB
/
ReminderTriggered.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace App\Notifications;
use App\Models\UserNotificationChannel;
use App\Models\UserNotificationSent;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use NotificationChannels\Telegram\TelegramMessage;
class ReminderTriggered extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(
private UserNotificationChannel $channel,
private string $content,
private string $contactName
) {
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
if ($this->channel->type === UserNotificationChannel::TYPE_EMAIL) {
return ['mail'];
}
if ($this->channel->type === UserNotificationChannel::TYPE_TELEGRAM) {
return ['telegram'];
}
return [];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
UserNotificationSent::create([
'user_notification_channel_id' => $this->channel->id,
'sent_at' => Carbon::now(),
'subject_line' => $this->content,
]);
return (new MailMessage())
->subject(trans('email.notification_reminder_email', ['name' => $this->contactName]))
->line(trans('email.reminder_triggered_intro'))
->line($this->content)
->line(trans('email.reminder_triggered_for'))
->line($this->contactName)
->line(trans('email.reminder_triggered_signature'));
}
public function toTelegram($notifiable)
{
UserNotificationSent::create([
'user_notification_channel_id' => $this->channel->id,
'sent_at' => Carbon::now(),
'subject_line' => $this->content,
]);
return TelegramMessage::create()
->to($this->channel->content)
->content($this->content);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}