Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: use new place for settings and topic IDs for telegram

peaklabs-dev4d23835119be
diff --git a/app/Notifications/Channels/TelegramChannel.php b/app/Notifications/Channels/TelegramChannel.php
index 958c46c21f..17d76181a1 100644
--- a/app/Notifications/Channels/TelegramChannel.php
+++ b/app/Notifications/Channels/TelegramChannel.php
@@ -9,38 +9,32 @@ class TelegramChannel
public function send($notifiable, $notification): void
{
$data = $notification->toTelegram($notifiable);
- $telegramData = $notifiable->routeNotificationForTelegram();
+ $settings = $notifiable->telegramNotificationSettings;
+
$message = data_get($data, 'message');
$buttons = data_get($data, 'buttons', []);
- $telegramToken = data_get($telegramData, 'token');
- $chatId = data_get($telegramData, 'chat_id');
- $topicId = null;
- $topicsInstance = get_class($notification);
+ $telegramToken = $settings->telegram_token;
+ $chatId = $settings->telegram_chat_id;
+
+ $topicId = match (get_class($notification)) {
+ \App\Notifications\Test::class => $settings->telegram_notifications_test_topic_id,
+ \App\Notifications\Application\StatusChanged::class,
+ \App\Notifications\Container\ContainerRestarted::class,
+ \App\Notifications\Container\ContainerStopped::class => $settings->telegram_notifications_status_change_topic_id,
+ \App\Notifications\Application\DeploymentSuccess::class => $settings->telegram_notifications_deployment_success_topic_id,
+ \App\Notifications\Application\DeploymentFailed::class => $settings->telegram_notifications_deployment_failure_topic_id,
+ \App\Notifications\Database\BackupSuccess::class => $settings->telegram_notifications_backup_success_topic_id,
+ \App\Notifications\Database\BackupFailed::class => $settings->telegram_notifications_backup_failure_topic_id,
+ \App\Notifications\ScheduledTask\TaskFailed::class => $settings->telegram_notifications_scheduled_task_failure_topic_id,
+ \App\Notifications\Server\Unreachable::class => $settings->telegram_notifications_server_unreachable_topic_id,
+ \App\Notifications\Server\Reachable::class => $settings->telegram_notifications_server_reachable_topic_id,
+ default => null,
+ };
- switch ($topicsInstance) {
- case \App\Notifications\Test::class:
- $topicId = data_get($notifiable, 'telegram_notifications_test_message_thread_id');
- break;
- case \App\Notifications\Application\StatusChanged::class:
- case \App\Notifications\Container\ContainerRestarted::class:
- case \App\Notifications\Container\ContainerStopped::class:
- $topicId = data_get($notifiable, 'telegram_notifications_status_changes_message_thread_id');
- break;
- case \App\Notifications\Application\DeploymentSuccess::class:
- case \App\Notifications\Application\DeploymentFailed::class:
- $topicId = data_get($notifiable, 'telegram_notifications_deployments_message_thread_id');
- break;
- case \App\Notifications\Database\BackupSuccess::class:
- case \App\Notifications\Database\BackupFailed::class:
- $topicId = data_get($notifiable, 'telegram_notifications_database_backups_message_thread_id');
- break;
- case \App\Notifications\ScheduledTask\TaskFailed::class:
- $topicId = data_get($notifiable, 'telegram_notifications_scheduled_tasks_thread_id');
- break;
- }
if (! $telegramToken || ! $chatId || ! $message) {
return;
}
+
SendMessageToTelegramJob::dispatch($message, $buttons, $telegramToken, $chatId, $topicId);
}
}