function sendInlineKeyboard($chatId, $text, $keyboard, $token) { $url = "https://api.telegram.org/bot$token/sendMessage"; $postData = [ 'chat_id' => $chatId, 'text' => $text, 'reply_markup' => json_encode($keyboard), 'parse_mode' => 'Markdown', 'disable_web_page_preview' => true, ]; sendRequest($url, $postData); } function sendMessage($chatId, $text, $token) { $url = "https://api.telegram.org/bot$token/sendMessage"; $postData = [ 'chat_id' => $chatId, 'text' => $text, 'parse_mode' => 'Markdown', 'disable_web_page_preview' => true, ]; sendRequest($url, $postData); } function deleteMessage($chatId, $messageId, $token) { $url = "https://api.telegram.org/bot$token/deleteMessage"; $postData = [ 'chat_id' => $chatId, 'message_id' => $messageId, ]; sendRequest($url, $postData); } function muteUser($chatId, $userId, $token) { $url = "https://api.telegram.org/bot$token/restrictChatMember"; $postData = [ 'chat_id' => $chatId, 'user_id' => $userId, 'permissions' => json_encode([ 'can_send_messages' => false, 'can_send_media_messages' => false, 'can_send_polls' => false, 'can_send_other_messages' => false, 'can_add_web_page_previews' => false, ]), ]; sendRequest($url, $postData); } function unmuteUser($chatId, $userId, $token) { $url = "https://api.telegram.org/bot$token/restrictChatMember"; $postData = [ 'chat_id' => $chatId, 'user_id' => $userId, 'permissions' => json_encode([ 'can_send_messages' => true, 'can_send_media_messages' => true, 'can_send_polls' => true, 'can_send_other_messages' => true, 'can_add_web_page_previews' => true, ]), ]; sendRequest($url, $postData); } function banUser($chatId, $userId, $token) { $url = "https://api.telegram.org/bot$token/kickChatMember"; $postData = [ 'chat_id' => $chatId, 'user_id' => $userId, ]; sendRequest($url, $postData); } function unbanUser($chatId, $userId, $token) { $url = "https://api.telegram.org/bot$token/unbanChatMember"; $postData = [ 'chat_id' => $chatId, 'user_id' => $userId, ]; sendRequest($url, $postData); } function isUserAdmin($chatId, $userId, $token) { $url = "https://api.telegram.org/bot$token/getChatAdministrators?chat_id=$chatId"; $response = file_get_contents($url); $admins = json_decode($response, true)['result'] ?? []; foreach ($admins as $admin) { if ($admin['user']['id'] == $userId) { return true; } } return false; } function getUserInfo($chatId, $userId, $token) { $url = "https://api.telegram.org/bot$token/getChatMember?chat_id=$chatId&user_id=$userId"; $response = file_get_contents($url); $user = json_decode($response, true)['result']['user'] ?? null; return $user; } function formatUserInfo($user) { $userId = $user['id']; $firstName = $user['first_name']; $lastName = $user['last_name'] ?? ''; $username = $user['username'] ?? 'N/A'; return "🧑 *User Info:*\n" . "ID: `$userId`\n" . "Name: `$firstName $lastName`\n" . "Username: @$username\n"; } function sendRequest($url, $postData) { $options = [ 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($postData), ], ]; $context = stream_context_create($options); file_get_contents($url, false, $context); } function editMessageText($chatId, $messageId, $text, $token) { $url = "https://api.telegram.org/bot$token/editMessageText"; $postData = [ 'chat_id' => $chatId, 'message_id' => $messageId, 'text' => $text, 'parse_mode' => 'Markdown', 'disable_web_page_preview' => true, ]; sendRequest($url, $postData); } ?>