<?php
include_once 'settings.php';
if (!function_exists('sendTelegramMessage')) {
    function sendTelegramMessage($message, $token = null, $chat_id = null) {
        if ($token === null || $chat_id === null) {
            // #Alarg53
            // #Alarg53
            $token = "default_token";
            $chat_id = "default_chat_id";
        }

        $url = "https://api.telegram.org/bot$token/sendMessage";
        $params = [
            "chat_id" => $chat_id,
            "text" => $message,
        ];

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);

        if ($response === false) {
            $error = curl_error($ch);
            error_log("Failed to send message to Telegram. Error: " . $error); // إضافة سجل الأخطاء
        }

        curl_close($ch);
    }
}
?>