From 4bb518f4ba4ee9ac3d7bed9da3c3940c995fa25e Mon Sep 17 00:00:00 2001 From: janis steiner Date: Wed, 6 May 2026 18:41:44 +0200 Subject: [PATCH] fix telegram --- src/Notifier/TelegramNotifier.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Notifier/TelegramNotifier.php b/src/Notifier/TelegramNotifier.php index bbc3be9..34ce982 100644 --- a/src/Notifier/TelegramNotifier.php +++ b/src/Notifier/TelegramNotifier.php @@ -15,9 +15,9 @@ class TelegramNotifier ) { $this->botToken = $this->repo->getConfig('telegram_bot_token'); $this->chatId = $this->repo->getConfig('telegram_chat_id'); - fprintf(STDERR, "Telegram: bot_token=%s, chat_id=%s\n", + error_log(sprintf("Telegram: bot_token=%s, chat_id=%s", $this->botToken ? substr($this->botToken, 0, 8) . '...' : 'EMPTY', - $this->chatId ?? 'EMPTY'); + $this->chatId ?? 'EMPTY')); } public function isConfigured(): bool @@ -28,11 +28,11 @@ class TelegramNotifier public function send(Alert $alert): bool { if (!$this->isConfigured()) { - fprintf(STDERR, "Telegram: not configured, skipping alert #%d\n", $alert->id); + error_log("Telegram: not configured, skipping alert #{$alert->id}"); return false; } - fprintf(STDERR, "Telegram: sending alert #%d [%s]...\n", $alert->id, $alert->severity->value); + error_log("Telegram: sending alert #{$alert->id} [{$alert->severity->value}]..."); $emoji = match ($alert->severity->value) { 'emergency', 'critical_high', 'critical' => "\xF0\x9F\x94\xA5", @@ -54,7 +54,7 @@ class TelegramNotifier $url = 'https://api.telegram.org/bot' . $this->botToken . '/sendMessage'; - fprintf(STDERR, "Telegram: POST %s\n", preg_replace('/bot.*\//', 'botTOKEN/', $url)); + error_log("Telegram: POST " . preg_replace('/bot.*\//', 'botTOKEN/', $url)); $postData = http_build_query([ 'chat_id' => $this->chatId, @@ -62,7 +62,7 @@ class TelegramNotifier 'parse_mode' => 'Markdown', 'disable_web_page_preview' => true, ]); - fprintf(STDERR, "Telegram: post data length=%d, text length=%d\n", strlen($postData), strlen($text)); + error_log("Telegram: post data length=" . strlen($postData) . ", text length=" . strlen($text)); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); @@ -76,14 +76,14 @@ class TelegramNotifier $curlError = curl_error($ch); curl_close($ch); - fprintf(STDERR, "Telegram: HTTP %d, curl_error=%s, response=%s\n", $httpCode, $curlError, substr($response, 0, 500)); + error_log("Telegram: HTTP $httpCode, curl_error=$curlError, response=" . substr($response, 0, 500)); if ($httpCode !== 200) { - fprintf(STDERR, "Telegram send failed (HTTP %d): %s\n", $httpCode, $response); + error_log("Telegram send failed (HTTP $httpCode): $response"); return false; } - fprintf(STDERR, "Telegram: sent successfully\n"); + error_log("Telegram: sent successfully"); return true; } } \ No newline at end of file