|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Usamamuneerchaudhary\Notifier\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Support\Facades\File; |
|
7
|
|
|
|
|
8
|
|
|
class NotifierInstallCommand extends Command |
|
9
|
|
|
{ |
|
10
|
|
|
protected $signature = 'notifier:install {--force : Overwrite existing files}'; |
|
11
|
|
|
protected $description = 'Install the Filament Notifier package'; |
|
12
|
|
|
|
|
13
|
|
|
public function handle() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->info('Installing Filament Notifier...'); |
|
16
|
|
|
|
|
17
|
|
|
// Publish config file |
|
18
|
|
|
$this->call('vendor:publish', [ |
|
19
|
|
|
'--provider' => 'Usamamuneerchaudhary\Notifier\NotifierServiceProvider', |
|
20
|
|
|
'--force' => $this->option('force'), |
|
21
|
|
|
]); |
|
22
|
|
|
|
|
23
|
|
|
// Run migrations |
|
24
|
|
|
$this->info('Running migrations...'); |
|
25
|
|
|
$this->call('migrate'); |
|
26
|
|
|
|
|
27
|
|
|
// Create sample data |
|
28
|
|
|
if ($this->confirm('Would you like to create sample notification channels and templates?')) { |
|
29
|
|
|
$this->createSampleData(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->info('Filament Notifier has been installed successfully!'); |
|
33
|
|
|
$this->info('You can now access the notification management panel in your Filament admin.'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
private function createSampleData() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->info('Creating sample data...'); |
|
39
|
|
|
|
|
40
|
|
|
// Create sample channels |
|
41
|
|
|
$channels = [ |
|
42
|
|
|
[ |
|
43
|
|
|
'title' => 'Email Notifications', |
|
44
|
|
|
'type' => 'email', |
|
45
|
|
|
'icon' => 'heroicon-o-envelope', |
|
46
|
|
|
'is_active' => true, |
|
47
|
|
|
'settings' => [ |
|
48
|
|
|
'smtp_host' => 'smtp.mailtrap.io', |
|
49
|
|
|
'smtp_port' => 2525, |
|
50
|
|
|
], |
|
51
|
|
|
], |
|
52
|
|
|
[ |
|
53
|
|
|
'title' => 'Slack Notifications', |
|
54
|
|
|
'type' => 'slack', |
|
55
|
|
|
'icon' => 'heroicon-o-chat-bubble-left-right', |
|
56
|
|
|
'is_active' => true, |
|
57
|
|
|
'settings' => [ |
|
58
|
|
|
'webhook_url' => env('SLACK_WEBHOOK_URL', ''), |
|
59
|
|
|
], |
|
60
|
|
|
], |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
foreach ($channels as $channelData) { |
|
64
|
|
|
\Usamamuneerchaudhary\Notifier\Models\NotificationChannel::firstOrCreate( |
|
65
|
|
|
['type' => $channelData['type']], |
|
66
|
|
|
$channelData |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
// Create sample events first |
|
71
|
|
|
$events = [ |
|
72
|
|
|
[ |
|
73
|
|
|
'group' => 'User Management', |
|
74
|
|
|
'name' => 'User Registered', |
|
75
|
|
|
'key' => 'user.registered', |
|
76
|
|
|
'description' => 'Triggered when a new user registers', |
|
77
|
|
|
'is_active' => true, |
|
78
|
|
|
], |
|
79
|
|
|
[ |
|
80
|
|
|
'group' => 'User Management', |
|
81
|
|
|
'name' => 'Password Reset Requested', |
|
82
|
|
|
'key' => 'password.reset', |
|
83
|
|
|
'description' => 'Triggered when a user requests password reset', |
|
84
|
|
|
'is_active' => true, |
|
85
|
|
|
], |
|
86
|
|
|
]; |
|
87
|
|
|
|
|
88
|
|
|
foreach ($events as $eventData) { |
|
89
|
|
|
\Usamamuneerchaudhary\Notifier\Models\NotificationEvent::firstOrCreate( |
|
90
|
|
|
['key' => $eventData['key']], |
|
91
|
|
|
$eventData |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
// Create sample templates |
|
96
|
|
|
$templates = [ |
|
97
|
|
|
[ |
|
98
|
|
|
'name' => 'Welcome Email', |
|
99
|
|
|
'event_key' => 'user.registered', |
|
100
|
|
|
'subject' => 'Welcome to {{app_name}}, {{name}}!', |
|
101
|
|
|
'content' => "Hi {{name}},\n\nWelcome to {{app_name}}! We're excited to have you on board.\n\nBest regards,\nThe {{app_name}} Team", |
|
102
|
|
|
'variables' => [ |
|
103
|
|
|
'name' => 'User\'s full name', |
|
104
|
|
|
'app_name' => 'Application name', |
|
105
|
|
|
], |
|
106
|
|
|
], |
|
107
|
|
|
[ |
|
108
|
|
|
'name' => 'Password Reset', |
|
109
|
|
|
'event_key' => 'password.reset', |
|
110
|
|
|
'subject' => 'Reset Your Password', |
|
111
|
|
|
'content' => "Hi {{name}},\n\nYou requested a password reset. Click the link below to reset your password:\n\n{{reset_link}}\n\nIf you didn't request this, please ignore this email.\n\nBest regards,\nThe {{app_name}} Team", |
|
112
|
|
|
'variables' => [ |
|
113
|
|
|
'name' => 'User\'s full name', |
|
114
|
|
|
'reset_link' => 'Password reset link', |
|
115
|
|
|
'app_name' => 'Application name', |
|
116
|
|
|
], |
|
117
|
|
|
], |
|
118
|
|
|
]; |
|
119
|
|
|
|
|
120
|
|
|
foreach ($templates as $templateData) { |
|
121
|
|
|
\Usamamuneerchaudhary\Notifier\Models\NotificationTemplate::firstOrCreate( |
|
122
|
|
|
['name' => $templateData['name'], 'event_key' => $templateData['event_key']], |
|
123
|
|
|
$templateData |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
$this->info('Sample data created successfully!'); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|