coolify/app/Notifications/Channels/TelegramChannel.php

40 lines
1.5 KiB
PHP
Raw Normal View History

2023-09-06 14:31:38 +02:00
<?php
namespace App\Notifications\Channels;
use App\Jobs\SendMessageToTelegramJob;
class TelegramChannel
{
public function send($notifiable, $notification): void
{
$data = $notification->toTelegram($notifiable);
$telegramData = $notifiable->routeNotificationForTelegram();
$message = data_get($data, 'message');
$buttons = data_get($data, 'buttons', []);
$telegramToken = data_get($telegramData, 'token');
$chatId = data_get($telegramData, 'chat_id');
2023-09-08 14:15:28 +02:00
$topicId = null;
$topicsInstance = get_class($notification);
2023-09-06 14:31:38 +02:00
2023-09-08 14:15:28 +02:00
switch ($topicsInstance) {
case 'App\Notifications\StatusChange':
$topicId = data_get($notifiable, 'telegram_notifications_status_changes_message_thread_id');
break;
case 'App\Notifications\Test':
$topicId = data_get($notifiable, 'telegram_notifications_test_message_thread_id');
break;
case 'App\Notifications\Deployment':
$topicId = data_get($notifiable, 'telegram_notifications_deployments_message_thread_id');
break;
case 'App\Notifications\DatabaseBackup':
$topicId = data_get($notifiable, 'telegram_notifications_database_backups_message_thread_id');
break;
}
2023-09-06 14:31:38 +02:00
if (!$telegramToken || !$chatId || !$message) {
2023-09-08 16:16:28 +02:00
return;
2023-09-06 14:31:38 +02:00
}
2023-09-08 14:15:28 +02:00
dispatch(new SendMessageToTelegramJob($message, $buttons, $telegramToken, $chatId, $topicId));
2023-09-06 14:31:38 +02:00
}
}