function sendTelegramMessage(int|string $chatId, string $text, ?array $replyMarkup = null): void { $config = appConfig(); $url = "https://api.telegram.org/bot{$config['8758737407:AAH-u7j-mOCDayZVcO776E23iw1kh4Q0sgs']}/sendMessage"; $payload = [ 'chat_id' => $chatId, 'text' => $text, ]; if ($replyMarkup !== null) { $payload['reply_markup'] = json_encode($replyMarkup); } $options = [ 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($payload), 'timeout' => 15, ] ]; $result = file_get_contents($url, false, stream_context_create($options)); file_put_contents( __DIR__ . '/send-debug.txt', date('Y-m-d H:i:s') . " URL: " . $url . "\nPAYLOAD: " . print_r($payload, true) . "\nRESULT: " . print_r($result, true) . "\n\n", FILE_APPEND ); }