Skip to content

Commit

Permalink
Merge pull request #4 from Thiritin/optional-telegram
Browse files Browse the repository at this point in the history
Optional telegram
  • Loading branch information
Thiritin authored Aug 21, 2024
2 parents 3c1c9b0 + 6ef2897 commit 2f3b0c5
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 14 deletions.
7 changes: 5 additions & 2 deletions app/Listeners/EmergencyNotificationsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public function __construct()

public function handle(EmergencyEvent $event): void
{
\Illuminate\Support\Facades\Notification::route('telegram', config('services.telegram-bot-api.chat_id'))
->notify(new EmergencyNotification($event->user, $event->type, $event->screens));
if (config('services.telegram-bot-api.chat_id'))
{
\Illuminate\Support\Facades\Notification::route('telegram', config('services.telegram-bot-api.chat_id'))
->notify(new EmergencyNotification($event->user, $event->type, $event->screens));
}
}
}
7 changes: 5 additions & 2 deletions app/Listeners/Screens/NotifyAdminScreenAvailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public function __construct()

public function handle(FirstPingEvent $event): void
{
\Illuminate\Support\Facades\Notification::route('telegram', config('services.telegram-bot-api.chat_id'))
->notify(new ScreenFirstTimeNotification($event->screen));
if (config('services.telegram-bot-api.chat_id'))
{
\Illuminate\Support\Facades\Notification::route('telegram', config('services.telegram-bot-api.chat_id'))
->notify(new ScreenFirstTimeNotification($event->screen));
}
}
}
8 changes: 6 additions & 2 deletions app/Listeners/Screens/NotifyAdminScreenOffline.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public function handle(OfflineEvent $event): void
if($event->screen->provisioned === false) {
return;
}
\Illuminate\Support\Facades\Notification::route('telegram', config('services.telegram-bot-api.chat_id'))
->notify(new ScreenOfflineNotification($event->screen));

if (config('services.telegram-bot-api.chat_id'))
{
\Illuminate\Support\Facades\Notification::route('telegram', config('services.telegram-bot-api.chat_id'))
->notify(new ScreenOfflineNotification($event->screen));
}
}
}
10 changes: 7 additions & 3 deletions app/Listeners/Screens/NotifyAdminScreenOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ public function __construct()
*/
public function handle(OnlineEvent $event): void
{
if($event->screen->provisioned === false) {
if ($event->screen->provisioned === false) {
return;
}
\Illuminate\Support\Facades\Notification::route('telegram', config('services.telegram-bot-api.chat_id'))
->notify(new ScreenOnlineNotification($event->screen));

if (config('services.telegram-bot-api.chat_id'))
{
\Illuminate\Support\Facades\Notification::route('telegram', config('services.telegram-bot-api.chat_id'))
->notify(new ScreenOnlineNotification($event->screen));
}
}
}
9 changes: 8 additions & 1 deletion app/Notifications/EmergencyNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ public function __construct(

public function via(): array
{
return ['telegram','admin'];
$notifications = ['admin'];

if (config('services.telegram-bot-api.chat_id'))
{
$notifications[] = 'telegram';
}

return $notifications;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion app/Notifications/ScreenFirstTimeNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public function __construct(readonly private Screen $screen)

public function via(): array
{
return ['telegram','admin'];
$notifications = ['admin'];

if (config('services.telegram-bot-api.chat_id'))
{
$notifications[] = 'telegram';
}

return $notifications;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion app/Notifications/ScreenOfflineNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public function __construct(readonly public Screen $screen)

public function via(): array
{
return ['telegram','admin'];
$notifications = ['admin'];

if (config('services.telegram-bot-api.chat_id'))
{
$notifications[] = 'telegram';
}

return $notifications;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion app/Notifications/ScreenOnlineNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public function __construct(readonly private Screen $screen)

public function via(): array
{
return ['telegram','admin'];
$notifications = ['admin'];

if (config('services.telegram-bot-api.chat_id'))
{
$notifications[] = 'telegram';
}

return $notifications;
}

/**
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3'
services:
laravel.test:
build:
Expand Down

0 comments on commit 2f3b0c5

Please sign in to comment.