connect_error) { error_log("DB Error: " . $conn->connect_error); exit; } // Read Telegram update $update = json_decode(file_get_contents('php://input'), true); $messageData = $update['message'] ?? $update['edited_message'] ?? null; if (!$messageData || !isset($messageData['text'])) exit; $message = trim($messageData['text']); $chat_id = $messageData['chat']['id']; $username = $messageData['from']['username'] ?? ''; $user_id = $messageData['from']['id']; function send_message($chat_id, $text) { global $bot_token; $keyboard = [ "keyboard" => [ ["/start", "/Traderid", "/Admin"] ], "resize_keyboard" => true, "one_time_keyboard" => false, "selective" => true ]; $url = "https://api.telegram.org/bot$bot_token/sendMessage"; $data = [ "chat_id" => $chat_id, "text" => $text, "parse_mode" => "HTML", "disable_web_page_preview" => true, "reply_markup" => json_encode($keyboard) ]; $options = [ 'http' => [ 'method' => 'POST', 'header' => "Content-Type: application/json", 'content' => json_encode($data) ] ]; $context = stream_context_create($options); file_get_contents($url, false, $context); } // Handle /start if (preg_match('/^\/start$/i', $message)) { $stmt = $conn->prepare("INSERT INTO users (chat_id, is_vip) VALUES (?, 0) ON DUPLICATE KEY UPDATE chat_id=chat_id"); $stmt->bind_param("i", $chat_id); $stmt->execute(); $stmt->close(); $welcome = <<⭐️ Open an account using the link below, make a deposit, and join the VIP.
πŸ”˜ VIP links are provided below: πŸ‡§πŸ‡© Link for Bangladesh: πŸ‘‰ Click here 🌍 Global (WORLD) link: πŸ‘‰ Click here πŸŽ₯ How to create an account: πŸ‘‰ Click here πŸŽ₯ How to make a deposit: πŸ‘‰ Click here
MSG; send_message($chat_id, $welcome); send_message($chat_id, "
Press the /Traderid command to check your trader ID.
"); exit; } // Handle /Traderid if (preg_match('/^\/Traderid$/i', $message)) { $stmt = $conn->prepare("REPLACE INTO user_states (telegram_user_id, waiting_for_trader_id) VALUES (?, 1)"); $stmt->bind_param("i", $user_id); $stmt->execute(); $stmt->close(); send_message($chat_id, "βœ… Please enter your trader ID below ⬇️"); exit; } // Handle /Admin command if (preg_match('/^\/Admin$/i', $message)) { $stmt = $conn->prepare("INSERT INTO users (chat_id, is_vip) VALUES (?, 0) ON DUPLICATE KEY UPDATE chat_id=chat_id"); $stmt->bind_param("i", $chat_id); $stmt->execute(); $stmt->close(); $admin_msg = <<🌍 Admin ID: πŸ‘‰ Click here πŸ“Œ For any issues or help, please contact directly. MSG; send_message($chat_id, $admin_msg); exit; } // Check waiting status for Traderid input $stmt = $conn->prepare("SELECT waiting_for_trader_id FROM user_states WHERE telegram_user_id = ?"); $stmt->bind_param("i", $user_id); $stmt->execute(); $stmt->bind_result($waiting); $stmt->fetch(); $stmt->close(); if ($waiting == 1 && !preg_match('/^\/\w+/', $message)) { $trader_id = htmlspecialchars(trim($message)); // Clear waiting state first $stmt = $conn->prepare("DELETE FROM user_states WHERE telegram_user_id = ?"); $stmt->bind_param("i", $user_id); $stmt->execute(); $stmt->close(); // Check if trader ID exists $stmt = $conn->prepare("SELECT reg, payout FROM postbacks WHERE trader_id = ? ORDER BY id DESC LIMIT 1"); $stmt->bind_param("s", $trader_id); $stmt->execute(); $stmt->bind_result($reg, $payout); $found = $stmt->fetch(); if (!$found) { $stmt->close(); $error_msg = "βœ–οΈYour trader ID is not registered through our link.\n\n"; $error_msg .= "
Please create a new ID using the following links:\n\n"; $error_msg .= "πŸ‡§πŸ‡© Link for Bangladesh:\n"; $error_msg .= 'Click here' . "\n\n"; $error_msg .= "🌍 Global (WORLD) link:\n"; $error_msg .= 'Click here' . "
"; send_message($chat_id, $error_msg); exit; } $stmt->close(); if ((float)$payout >= 20.00) { // Check if already has invite links $stmt = $conn->prepare("SELECT telegram_user_id, invite_link FROM invite_logs WHERE trader_id = ?"); $stmt->bind_param("s", $trader_id); $stmt->execute(); $stmt->bind_result($existing_user_id, $existing_link); if ($stmt->fetch()) { $stmt->close(); if ($existing_user_id == $user_id) { $success_msg = "πŸŽ‰ Your access links are ready!\n\n"; $success_msg .= "πŸ“Œ Join the following groups to be part of our community:\n\n"; $success_msg .= "πŸ”Ή Click Here To Join Now\n"; $success_msg .= "βœ… For any issues or questions, feel free to contact us.\n\n"; $success_msg .= "Happy trading! πŸš€"; send_message($chat_id, $success_msg); } else { send_message($chat_id, "βœ–οΈThis trader ID is already linked to another Telegram account."); } } else { $stmt->close(); // Create new invite links $links = []; $group_ids = [$group_chat_id]; $all_success = true; foreach ($group_ids as $group_id) { $link = create_invite_link($group_id, $bot_token); if ($link) { $links[] = $link; } else { $all_success = false; break; } } if ($all_success && count($links) === 1) { $success_msg = "πŸŽ‰ Your access links are ready!\n\n"; $success_msg .= "πŸ“Œ Join the groups below to become part of our community:\n\n"; $success_msg .= "πŸ”Ή Click Here To Join Now \n"; $success_msg .= "βœ… For any issues or questions, feel free to contact us.\n\n"; $success_msg .= "Happy trading! πŸš€"; send_message($chat_id, $success_msg); // Store all four links in the database $current_time = date('Y-m-d H:i:s'); $stmt = $conn->prepare("INSERT INTO invite_logs (trader_id, telegram_user, telegram_user_id, invite_link, invited_at) VALUES (?, ?, ?, ?, ?)"); $stmt->bind_param("ssiss", $trader_id, $username, $user_id, $links[0], // first link $current_time ); $stmt->execute(); $stmt->close(); } else { send_message($chat_id, "❌ Failed to generate access link. Please contact the admin."); } } } else { send_message($chat_id, "πŸ”” You have successfully registered.\n\nTo get access to the group, please deposit $20 or more.\n\nAfter depositing, use the /Traderid command again to check."); } exit; } $conn->close(); function create_invite_link($chat_id, $bot_token) { $url = "https://api.telegram.org/bot$bot_token/createChatInviteLink"; $post_fields = array( 'chat_id' => $chat_id, 'member_limit' => 1, 'creates_join_request' => false ); $options = array( 'http' => array( 'header' => "Content-type: application/json", 'method' => 'POST', 'content' => json_encode($post_fields), ), ); $context = stream_context_create($options); $response = file_get_contents($url, false, $context); $json = json_decode($response, true); if ($json && isset($json['ok']) && $json['ok']) { return $json['result']['invite_link']; } return false; } ?>