Add token validation and logging for Telegram bot

This commit is contained in:
mwpn
2026-01-26 10:05:16 +07:00
parent 62ec2ac418
commit b08291db84

View File

@@ -10,7 +10,17 @@ class TelegramHelper
public static function init() public static function init()
{ {
self::$botToken = $_ENV['TELEGRAM_BOT_TOKEN'] ?? ''; self::$botToken = $_ENV['TELEGRAM_BOT_TOKEN'] ?? '';
if (empty(self::$botToken)) {
self::log("ERROR: TELEGRAM_BOT_TOKEN is empty or not set in .env");
throw new \Exception("Telegram Bot Token is not configured");
}
self::$apiURL = "https://api.telegram.org/bot" . self::$botToken . "/"; self::$apiURL = "https://api.telegram.org/bot" . self::$botToken . "/";
// Log token (masked for security)
$maskedToken = substr(self::$botToken, 0, 10) . '...' . substr(self::$botToken, -5);
self::log("TelegramHelper initialized with token: $maskedToken");
} }
/** /**