├── Procfile ├── requirements.txt ├── config.py ├── LICENSE ├── README.md ├── app.py └── status.html /Procfile: -------------------------------------------------------------------------------- 1 | web: python3 app.py -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | fastapi 2 | uvicorn 3 | pyrofork 4 | python-dateutil 5 | TgCrypto -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | #Copyright @ISmartCoder 2 | #Updates Channel: https://t.me/TheSmartDev 3 | # Telegram API credentials 4 | API_ID = your_api_id 5 | API_HASH = "your_api_hash" 6 | BOT_TOKEN = "Your_Bot_token" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 @ISmartCoder 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmartUserInfo 🌟 2 | 3 | SmartUserInfo is a powerful Telegram Info API built with FastAPI and Pyrogram, designed to retrieve detailed information about Telegram users, bots, channels, and groups. This API provides insights such as account age estimation, data center locations, premium status, and real-time status tracking. 💥 4 | 5 | **Project URL**: [github.com/TheSmartDevs/SmartUserInfo](https://github.com/TheSmartDevs/SmartUserInfo) ✅ 6 | 7 | **Updates Channel**: [t.me/TheSmartDev](https://t.me/TheSmartDev) 🌟 8 | 9 | **Developer**: [@ISmartCoder](https://t.me/ISmartCoder) 💥 10 | 11 | --- 12 | 13 | ## Features ✅ 14 | 15 | - **User & Bot Information** 🌟: Retrieve details like user ID, username, first/last name, premium status, verification status, and account flags (e.g., scam or fake). 16 | - **Channel & Group Details** 💥: Fetch information about Telegram channels, groups, and supergroups, including member count, description, and join links. 17 | - **Account Age Estimation** ✅: Estimate the account creation date based on user ID with a custom algorithm. 18 | - **Data Center Location** ❄️: Identify the Telegram data center location (e.g., Miami, Amsterdam, Singapore) for users and chats. 19 | - **Real-time Status Tracking** 🌟: Get the current status of users (e.g., online, offline, recently online). 20 | - **FastAPI Integration** 💥: Provides a robust, scalable API with endpoints for health checks, entity information, and interactive documentation. 21 | - **Pyrogram Backend** ✅: Leverages Pyrogram for reliable Telegram API interactions. 22 | - **Error Handling** ❄️: Comprehensive error handling for invalid usernames, channels, or other issues. 23 | - **Deployment Ready** 🌟: Easy setup instructions for Render, Heroku, or VPS. 24 | 25 | --- 26 | 27 | ## API Endpoints 💥 28 | 29 | | Endpoint | Description | Parameters | 30 | |------------------|--------------------------------------------|--------------------------------| 31 | | `/` | Serves the status dashboard (HTML) 🌟 | None | 32 | | `/info` | Retrieves Telegram entity information ✅ | `username` (query parameter) | 33 | | `/health` | API health check and detailed information ❄️ | None | 34 | | `/docs` | Interactive Swagger UI documentation 🌟 | None | 35 | | `/redoc` | Alternative ReDoc API documentation ✅ | None | 36 | 37 | ### Response Format 🌟 38 | 39 | The API returns JSON responses with a consistent structure: 40 | 41 | - **Success Response** ✅: 42 | ```json 43 | { 44 | "success": true, 45 | "type": "user|bot|group|supergroup|channel", 46 | "id": "", 47 | "first_name": "", // For users/bots 48 | "last_name": "", // For users/bots 49 | "username": "", 50 | "dc_id": , 51 | "dc_location": "", 52 | "is_premium": , // For users/bots 53 | "is_verified": , // For users/bots 54 | "is_bot": , // For users/bots 55 | "flags": "Clean|Scam|Fake", // For users/bots 56 | "status": "", // For users/bots 57 | "account_created": "", // For users/bots 58 | "account_age": "", // For users/bots 59 | "members_count": , // For groups/channels 60 | "description": "", // For groups/channels 61 | "api_dev": "@ISmartCoder", 62 | "api_updates": "https://t.me/TheSmartDev", 63 | "links": { 64 | "android": "", 65 | "ios": "", 66 | "permanent": "", 67 | "join": "" // For groups/channels 68 | } 69 | } 70 | ``` 71 | 72 | - **Error Response** ❌: 73 | ```json 74 | { 75 | "success": false, 76 | "error": "" 77 | } 78 | ``` 79 | 80 | --- 81 | 82 | ## Setup Instructions ❄️ 83 | 84 | ### Prerequisites 🌟 85 | 86 | - Python 3.8+ 87 | - Telegram API credentials (`API_ID`, `API_HASH`, `BOT_TOKEN`) ✅ 88 | - Obtain these from [my.telegram.org](https://my.telegram.org) and create a bot via [@BotFather](https://t.me/BotFather). 89 | - Git 90 | - A deployment platform (Render, Heroku, or VPS) 💥 91 | 92 | ### Local Setup ✅ 93 | 94 | 1. **Clone the Repository** 🌟: 95 | ```bash 96 | git clone https://github.com/TheSmartDevs/SmartUserInfo.git 97 | cd SmartUserInfo 98 | ``` 99 | 100 | 2. **Install Dependencies** 💥: 101 | ```bash 102 | pip install -r requirements.txt 103 | ``` 104 | Ensure `requirements.txt` includes: 105 | ``` 106 | fastapi 107 | uvicorn 108 | pyrogram 109 | python-dateutil 110 | ``` 111 | 112 | 3. **Configure Environment Variables** ✅: 113 | Create a `config.py` file in the project root with the following: 114 | ```python 115 | API_ID = "your_api_id" 116 | API_HASH = "your_api_hash" 117 | BOT_TOKEN = "your_bot_token" 118 | ``` 119 | 120 | 4. **Create Status Page** ❄️: 121 | Create a `status.html` file in the project root for the `/` endpoint. Example: 122 | ```html 123 | 124 | 125 | 126 | SmartUserInfo API 🌟 127 | 128 | 129 |

SmartUserInfo API 💥

130 |

API is running! Check API Docs for details. ✅

131 |

Developed by @ISmartCoder 🌟

132 |

Updates: t.me/TheSmartDev 💥

133 | 134 | 135 | ``` 136 | 137 | 5. **Run the Application** ✅: 138 | ```bash 139 | python app.py 140 | ``` 141 | The API will be available at `http://localhost:5000`. 142 | 143 | --- 144 | 145 | ### Deployment 💥 146 | 147 | #### 1. Deploy on Render 🌟 148 | 149 | 1. **Create a Render Account** ✅: 150 | Sign up at [render.com](https://render.com) and create a new Web Service. 151 | 152 | 2. **Connect GitHub Repository** ❄️: 153 | Link your GitHub repository (`github.com/TheSmartDevs/SmartUserInfo`) to Render. 154 | 155 | 3. **Configure Build Settings** ✅: 156 | - **Build Command**: `pip install -r requirements.txt` 157 | - **Start Command**: `python app.py` 158 | - **Environment Variables**: 159 | - `API_ID`: Your Telegram API ID 160 | - `API_HASH`: Your Telegram API Hash 161 | - `BOT_TOKEN`: Your Telegram Bot Token 162 | - `PORT`: `5000` (default) 163 | 164 | 4. **Add Status Page** 🌟: 165 | Ensure `status.html` is included in your repository. 166 | 167 | 5. **Deploy** 💥: 168 | Trigger the deployment from Render’s dashboard. The API will be accessible at the provided Render URL. 169 | 170 | #### 2. Deploy on Heroku ✅ 171 | 172 | [![Deploy to Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/TheSmartDevs/SmartUserInfo) 173 | 174 | 1. **Create a Heroku Account** 🌟: 175 | Sign up at [heroku.com](https://heroku.com). 176 | 177 | 2. **Deploy via Button** 💥: 178 | Click the "Deploy to Heroku" button above, or manually deploy: 179 | - Clone the repository and push to Heroku: 180 | ```bash 181 | heroku create 182 | git push heroku main 183 | ``` 184 | 185 | 3. **Configure Environment Variables** ✅: 186 | In the Heroku dashboard, add: 187 | - `API_ID` 188 | - `API_HASH` 189 | - `BOT_TOKEN` 190 | 191 | 4. **Add Buildpacks** ❄️: 192 | Add the Python buildpack in the Heroku dashboard or via: 193 | ```bash 194 | heroku buildpacks:set heroku/python 195 | ``` 196 | 197 | 5. **Add Status Page** 🌟: 198 | Ensure `status.html` is in the repository. 199 | 200 | 6. **Scale Dynos** ✅: 201 | ```bash 202 | heroku ps:scale web=1 203 | ``` 204 | 205 | 7. **Access the API** 💥: 206 | The API will be available at `https://your-app-name.herokuapp.com`. 207 | 208 | #### 3. Deploy on VPS ❄️ 209 | 210 | 1. **Set Up VPS** 🌟: 211 | Use a provider like DigitalOcean, AWS, or Linode. Install Ubuntu 20.04+. 212 | 213 | 2. **Install Dependencies** ✅: 214 | ```bash 215 | sudo apt update 216 | sudo apt install python3 python3-pip git 217 | ``` 218 | 219 | 3. **Clone Repository** 💥: 220 | ```bash 221 | git clone https://github.com/TheSmartDevs/SmartUserInfo.git 222 | cd SmartUserInfo 223 | pip3 install -r requirements.txt 224 | ``` 225 | 226 | 4. **Configure Environment Variables** ✅: 227 | Create a `config.py` file or export variables: 228 | ```bash 229 | export API_ID="your_api_id" 230 | export API_HASH="your_api_hash" 231 | export BOT_TOKEN="your_bot_token" 232 | ``` 233 | 234 | 5. **Add Status Page** 🌟: 235 | Create `status.html` as described in the local setup. 236 | 237 | 6. **Run with Uvicorn** 💥: 238 | ```bash 239 | uvicorn app:app --host 0.0.0.0 --port 5000 240 | ``` 241 | 242 | 7. **Set Up Reverse Proxy (Optional)** ❄️: 243 | Use Nginx to expose the API: 244 | ```bash 245 | sudo apt install nginx 246 | sudo nano /etc/nginx/sites-available/smartuser 247 | ``` 248 | Add: 249 | ```nginx 250 | server { 251 | listen 80; 252 | server_name your_domain_or_ip; 253 | location / { 254 | proxy_pass http://localhost:5000; 255 | proxy_set_header Host $host; 256 | proxy_set_header X-Real-IP $remote_addr; 257 | } 258 | } 259 | ``` 260 | Enable and restart Nginx: 261 | ```bash 262 | sudo ln -s /etc/nginx/sites-available/smartuser /etc/nginx/sites-enabled/ 263 | sudo systemctl restart nginx 264 | ``` 265 | 266 | 8. **Run in Background** ✅: 267 | Use `screen` or `pm2` to keep the app running: 268 | ```bash 269 | pip3 install pm2 270 | pm2 start "uvicorn app:app --host 0.0.0.0 --port 5000" --name smartuser 271 | ``` 272 | 273 | --- 274 | 275 | ## API Documentation 🌟 276 | 277 | - **Interactive Docs** ✅: Access at `/docs` (Swagger UI) or `/redoc` (ReDoc). 278 | - **Example Request** 💥: 279 | ```bash 280 | curl -X GET "http://your-api-url/info?username=ISmartCoder" 281 | ``` 282 | 283 | - **Example Response (User)** ✅: 284 | ```json 285 | { 286 | "success": true, 287 | "type": "user", 288 | "id": 123456789, 289 | "first_name": "Smart", 290 | "last_name": "Coder", 291 | "username": "ISmartCoder", 292 | "dc_id": 4, 293 | "dc_location": "STO, Stockholm, Sweden, SE", 294 | "is_premium": false, 295 | "is_verified": false, 296 | "is_bot": false, 297 | "flags": "Clean", 298 | "status": "Online", 299 | "account_created": "August 13, 2020", 300 | "account_age": "4 years, 10 months, 16 days", 301 | "api_dev": "@ISmartCoder", 302 | "api_updates": "https://t.me/TheSmartDev", 303 | "links": { 304 | "android": "tg://openmessage?user_id=123456789", 305 | "ios": "tg://user?id=123456789", 306 | "permanent": "tg://user?id=123456789" 307 | } 308 | } 309 | ``` 310 | 311 | - **Example Response (Channel)** 🌟: 312 | ```json 313 | { 314 | "success": true, 315 | "type": "channel", 316 | "id": -100123456789, 317 | "title": "TheSmartDev", 318 | "username": "TheSmartDev", 319 | "dc_id": 2, 320 | "dc_location": "AMS, Amsterdam, Netherlands, NL", 321 | "members_count": 1000, 322 | "description": "Updates for SmartUserInfo API", 323 | "api_dev": "@ISmartCoder", 324 | "api_updates": "https://t.me/TheSmartDev", 325 | "links": { 326 | "join": "t.me/TheSmartDev", 327 | "permanent": "t.me/TheSmartDev" 328 | } 329 | } 330 | ``` 331 | 332 | --- 333 | 334 | ## Contributing 💥 335 | 336 | Contributions are welcome! Please: 337 | 1. Fork the repository. 🌟 338 | 2. Create a new branch (`git checkout -b feature/your-feature`). ✅ 339 | 3. Commit your changes (`git commit -m 'Add your feature'`). ❄️ 340 | 4. Push to the branch (`git push origin feature/your-feature`). 💥 341 | 5. Open a pull request. ✅ 342 | 343 | --- 344 | 345 | ## License ✅ 346 | 347 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. 🌟 348 | 349 | --- 350 | 351 | ## Support ❄️ 352 | 353 | For support, join our updates channel: [t.me/TheSmartDev](https://t.me/TheSmartDev) or contact [@ISmartCoder](https://t.me/ISmartCoder). 💥 354 | 355 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | #Copyright @ISmartCoder 2 | #Updates Channel: https://t.me/TheSmartDev 3 | 4 | from datetime import datetime, timedelta 5 | from dateutil.relativedelta import relativedelta 6 | from pyrogram import Client 7 | from pyrogram.enums import ParseMode, ChatType, UserStatus 8 | from pyrogram.errors import PeerIdInvalid, UsernameNotOccupied, ChannelInvalid 9 | from fastapi import FastAPI, HTTPException, Query 10 | from fastapi.responses import JSONResponse, FileResponse 11 | import asyncio 12 | import logging 13 | from contextlib import asynccontextmanager 14 | from config import API_ID, API_HASH, BOT_TOKEN 15 | 16 | # Configure LOGGER Module 17 | logging.basicConfig(level=logging.INFO) 18 | LOGGER = logging.getLogger(__name__) 19 | 20 | # Global Client For Multi Event Loop Fix 21 | client = None 22 | 23 | def get_dc_locations(): 24 | """Custom DC Locations Measurement By @ISmartCoder""" 25 | return { 26 | 1: "MIA, Miami, USA, US", 27 | 2: "AMS, Amsterdam, Netherlands, NL", 28 | 3: "MBA, Mumbai, India, IN", 29 | 4: "STO, Stockholm, Sweden, SE", 30 | 5: "SIN, Singapore, SG", 31 | 6: "LHR, London, United Kingdom, GB", 32 | 7: "FRA, Frankfurt, Germany, DE", 33 | 8: "JFK, New York, USA, US", 34 | 9: "HKG, Hong Kong, HK", 35 | 10: "TYO, Tokyo, Japan, JP", 36 | 11: "SYD, Sydney, Australia, AU", 37 | 12: "GRU, São Paulo, Brazil, BR", 38 | 13: "DXB, Dubai, UAE, AE", 39 | 14: "CDG, Paris, France, FR", 40 | 15: "ICN, Seoul, South Korea, KR", 41 | } 42 | 43 | def calculate_account_age(creation_date): 44 | """Custom Function Age Calc""" 45 | today = datetime.now() 46 | delta = relativedelta(today, creation_date) 47 | years = delta.years 48 | months = delta.months 49 | days = delta.days 50 | return f"{years} years, {months} months, {days} days" 51 | 52 | def estimate_account_creation_date(user_id): 53 | """Approximate Results Get By @ISmartCoder""" 54 | reference_points = [ 55 | (100000000, datetime(2013, 8, 1)), 56 | (1273841502, datetime(2020, 8, 13)), 57 | (1500000000, datetime(2021, 5, 1)), 58 | (2000000000, datetime(2022, 12, 1)), 59 | ] 60 | 61 | closest_point = min(reference_points, key=lambda x: abs(x[0] - user_id)) 62 | closest_user_id, closest_date = closest_point 63 | 64 | id_difference = user_id - closest_user_id 65 | days_difference = id_difference / 20000000 66 | creation_date = closest_date + timedelta(days=days_difference) 67 | 68 | return creation_date 69 | 70 | def format_user_status(status): 71 | """Convert Status To String For JSON""" 72 | if not status: 73 | return "Unknown" 74 | 75 | status_map = { 76 | UserStatus.ONLINE: "Online", 77 | UserStatus.OFFLINE: "Offline", 78 | UserStatus.RECENTLY: "Recently online", 79 | UserStatus.LAST_WEEK: "Last seen within week", 80 | UserStatus.LAST_MONTH: "Last seen within month" 81 | } 82 | return status_map.get(status, "Unknown") 83 | 84 | async def get_user_info(username): 85 | """Fallback Function User To Bot""" 86 | try: 87 | DC_LOCATIONS = get_dc_locations() 88 | user = await client.get_users(username) 89 | 90 | premium_status = getattr(user, 'is_premium', False) 91 | dc_location = DC_LOCATIONS.get(user.dc_id, "Unknown") 92 | account_created = estimate_account_creation_date(user.id) 93 | account_created_str = account_created.strftime("%B %d, %Y") 94 | account_age = calculate_account_age(account_created) 95 | verified_status = getattr(user, 'is_verified', False) 96 | status = format_user_status(getattr(user, 'status', None)) 97 | 98 | # Scam Tag & Flags 99 | flags = "Clean" 100 | if getattr(user, 'is_scam', False): 101 | flags = "Scam" 102 | elif getattr(user, 'is_fake', False): 103 | flags = "Fake" 104 | 105 | user_data = { 106 | "success": True, 107 | "type": "bot" if user.is_bot else "user", 108 | "id": user.id, 109 | "first_name": user.first_name, 110 | "last_name": user.last_name, 111 | "username": user.username, 112 | "dc_id": user.dc_id, 113 | "dc_location": dc_location, 114 | "is_premium": premium_status, 115 | "is_verified": verified_status, 116 | "is_bot": user.is_bot, 117 | "flags": flags, 118 | "status": status, 119 | "account_created": account_created_str, 120 | "account_age": account_age, 121 | "api_dev": "@ISmartCoder", 122 | "api_updates": "https://t.me/TheSmartDev", 123 | "links": { 124 | "android": f"tg://openmessage?user_id={user.id}", 125 | "ios": f"tg://user?id={user.id}", 126 | "permanent": f"tg://user?id={user.id}" 127 | } 128 | } 129 | 130 | return user_data 131 | 132 | except (PeerIdInvalid, UsernameNotOccupied, IndexError): 133 | return {"success": False, "error": "User not found"} 134 | except Exception as e: 135 | LOGGER.error(f"Error fetching user info: {str(e)}") 136 | return {"success": False, "error": f"Failed to fetch user information: {str(e)}"} 137 | 138 | async def get_chat_info(username): 139 | """Group Channel Fallback Functions""" 140 | try: 141 | DC_LOCATIONS = get_dc_locations() 142 | chat = await client.get_chat(username) 143 | 144 | chat_type_map = { 145 | ChatType.SUPERGROUP: "supergroup", 146 | ChatType.GROUP: "group", 147 | ChatType.CHANNEL: "channel" 148 | } 149 | chat_type = chat_type_map.get(chat.type, "unknown") 150 | 151 | dc_location = DC_LOCATIONS.get(getattr(chat, 'dc_id', None), "Unknown") 152 | 153 | # Correct Link Generation 154 | if chat.username: 155 | join_link = f"t.me/{chat.username}" 156 | permanent_link = f"t.me/{chat.username}" 157 | elif chat.id < 0: 158 | chat_id_str = str(chat.id).replace('-100', '') 159 | join_link = f"t.me/c/{chat_id_str}/1" 160 | permanent_link = f"t.me/c/{chat_id_str}/1" 161 | else: 162 | join_link = f"tg://resolve?domain={chat.id}" 163 | permanent_link = f"tg://resolve?domain={chat.id}" 164 | 165 | chat_data = { 166 | "success": True, 167 | "type": chat_type, 168 | "id": chat.id, 169 | "title": chat.title, 170 | "username": chat.username, 171 | "dc_id": getattr(chat, 'dc_id', None), 172 | "dc_location": dc_location, 173 | "members_count": getattr(chat, 'members_count', None), 174 | "description": getattr(chat, 'description', None), 175 | "api_dev": "@ISmartCoder", 176 | "api_updates": "https://t.me/TheSmartDev", 177 | "links": { 178 | "join": join_link, 179 | "permanent": permanent_link 180 | } 181 | } 182 | 183 | return chat_data 184 | 185 | except (ChannelInvalid, PeerIdInvalid): 186 | return {"success": False, "error": "Chat not found or access denied"} 187 | except Exception as e: 188 | LOGGER.error(f"Error fetching chat info: {str(e)}") 189 | return {"success": False, "error": f"Failed to fetch chat information: {str(e)}"} 190 | 191 | async def get_telegram_info(username): 192 | """All Entinity Capture @ISmartCoder""" 193 | # Clean the username 194 | username = username.strip('@').replace('https://', '').replace('http://', '').replace('t.me/', '').replace('/', '').replace(':', '') 195 | 196 | LOGGER.info(f"Fetching info for: {username}") 197 | 198 | # UserBot To ChannelGroup Fallback 199 | user_info = await get_user_info(username) 200 | if user_info["success"]: 201 | return user_info 202 | 203 | # Main Fallback For GC 204 | chat_info = await get_chat_info(username) 205 | if chat_info["success"]: 206 | return chat_info 207 | 208 | # If both failed 209 | return {"success": False, "error": "User Not Found In My Database"} 210 | 211 | @asynccontextmanager 212 | async def lifespan(app: FastAPI): 213 | """Decorator Method For Conflict Remove By @ISmartCoder""" 214 | global client 215 | 216 | # Startup 217 | LOGGER.info("Creating Bot Client From BOT_TOKEN") 218 | client = Client( 219 | "GetUserInfo", 220 | api_id=API_ID, 221 | api_hash=API_HASH, 222 | bot_token=BOT_TOKEN 223 | ) 224 | LOGGER.info("Bot Client Created Successfully!") 225 | 226 | await client.start() 227 | LOGGER.info("Pyrogram client started successfully!") 228 | 229 | yield 230 | 231 | # Shutdown down pyro client 232 | if client: 233 | await client.stop() 234 | LOGGER.info("Pyrogram client stopped!") 235 | 236 | # Create FastAPI app with lifespan @ISmartCoder 237 | app = FastAPI( 238 | title="Telegram Info API", 239 | description="Get information about Telegram users, bots, channels, and groups", 240 | version="1.0.0", 241 | lifespan=lifespan 242 | ) 243 | 244 | @app.get("/info") 245 | async def info_endpoint(username: str = Query(..., description="Username, user ID, or Telegram link")): 246 | """API endpoint to get Telegram entity information""" 247 | try: 248 | result = await get_telegram_info(username) 249 | 250 | if result["success"]: 251 | return result 252 | else: 253 | raise HTTPException(status_code=404, detail=result["error"]) 254 | 255 | except HTTPException: 256 | raise 257 | except Exception as e: 258 | LOGGER.error(f"API error: {str(e)}") 259 | raise HTTPException(status_code=500, detail="Internal server error") 260 | 261 | @app.get("/health") 262 | async def health_check(): 263 | """Enhanced health check endpoint with detailed API information""" 264 | uptime = datetime.now().strftime("%Y-%m-%d %H:%M:%S") 265 | bot_status = "connected" if client and client.is_connected else "disconnected" 266 | 267 | return { 268 | "success": True, 269 | "status": "API is running smoothly ✅", 270 | "api_info": { 271 | "name": "Telegram Info API", 272 | "version": "1.0.0", 273 | "description": "Advanced Telegram entity information retrieval system", 274 | "uptime_check": uptime, 275 | "bot_status": f"Pyrofork Client: {bot_status}", 276 | "features": [ 277 | "User & Bot Information", 278 | "Channel & Group Details", 279 | "Account Age Estimation", 280 | "Data Center Location", 281 | "Premium Status Detection", 282 | "Verification Status", 283 | "Real-time Status Tracking" 284 | ] 285 | }, 286 | "endpoints": { 287 | "/": "Status Dashboard (HTML)", 288 | "/info": "Get Telegram entity information", 289 | "/health": "API health check and information", 290 | "/docs": "Interactive API documentation", 291 | "/redoc": "Alternative API documentation" 292 | }, 293 | "developer": { 294 | "created_by": "@ISmartCoder", 295 | "proudly_developed": " Proudly developed by @ISmartCoder ✅", 296 | "updates_channel": "https://t.me/TheSmartDev", 297 | "support": "Join our updates channel for latest features!" 298 | }, 299 | "stats": { 300 | "supported_entities": ["Users", "Bots", "Channels", "Groups", "Supergroups"], 301 | "data_centers": len(get_dc_locations()), 302 | "response_format": "JSON", 303 | "authentication": "Bot Token Based" 304 | } 305 | } 306 | 307 | @app.get("/") 308 | async def root(): 309 | """Root endpoint serving status.html""" 310 | try: 311 | return FileResponse("status.html", media_type="text/html") 312 | except Exception as e: 313 | # Fallback response if status.html is not found 314 | return { 315 | "success": False, 316 | "error": "status.html file not found", 317 | "message": "Please create status.html file in the root directory", 318 | "fallback_info": { 319 | "api_name": "Telegram Info API", 320 | "status": "Running", 321 | "developer": "@ISmartCoder", 322 | "updates_channel": "https://t.me/TheSmartDev" 323 | } 324 | } 325 | 326 | if __name__ == "__main__": 327 | import uvicorn 328 | LOGGER.info("Starting FastAPI server with Uvicorn...") 329 | uvicorn.run( 330 | "app:app", 331 | host="0.0.0.0", 332 | port=5000, 333 | log_level="info", 334 | reload=False 335 | ) -------------------------------------------------------------------------------- /status.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Telegram Info API - Cosmic Dashboard 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 179 | 180 | 181 |
182 |
183 |

Smart Telegram Info API

184 |

Dive into the cosmos of Telegram data with a stellar API experience.

185 |
186 | 187 | Checking API Server Status... 188 |
189 | Try Now 190 |
191 |
192 | 193 | 194 |
195 |

Get Telegram Entinites

196 |
197 |
198 | 199 | 207 | 211 |
212 |
213 | User 214 | Bot 215 | Channel 216 | Group 217 | Supergroup 218 |
219 | 220 |
221 | 222 |
223 | 224 | 225 |
226 |

API Entire Docs

227 |
228 |
229 |

GET /info

230 |

Retrieve data on Telegram entities (users, bots, channels, groups).

231 |
"request": "curl -X GET \"http://localhost:5000/info?username=@username\"",
232 | 
233 | "response_user": {
234 |   "success": true,
235 |   "type": "user",
236 |   "id": 123456789,
237 |   "first_name": "John",
238 |   "last_name": "Doe",
239 |   "username": "@username",
240 |   "dc_id": 2,
241 |   "dc_location": "AMS, Amsterdam, Netherlands, NL",
242 |   "is_premium": true,
243 |   "is_verified": false,
244 |   "is_bot": false,
245 |   "flags": "Clean",
246 |   "status": "Online",
247 |   "account_created": "January 01, 2020",
248 |   "account_age": "5 years, 6 months, 28 days",
249 |   "links": {
250 |     "android": "tg://openmessage?user_id=123456789",
251 |     "ios": "tg://user?id=123456789",
252 |     "permanent": "tg://user?id=123456789"
253 |   }
254 | },
255 | 
256 | "response_channel": {
257 |   "success": true,
258 |   "type": "channel",
259 |   "id": -100123456789,
260 |   "title": "Example Channel",
261 |   "username": "@ExampleChannel",
262 |   "dc_id": 4,
263 |   "dc_location": "STO, Stockholm, Sweden, SE",
264 |   "members_count": 10000,
265 |   "description": "Welcome to our channel!",
266 |   "links": {
267 |     "join": "t.me/ExampleChannel",
268 |     "permanent": "t.me/ExampleChannel"
269 |   }
270 | },
271 | 
272 | "response_error": {
273 |   "success": false,
274 |   "error": "Entity not found or access denied"
275 | }
276 | 
277 |
278 |
279 |

GET /health

280 |

Check the API's operational status.

281 |
"request": "curl -X GET \"http://localhost:5000/health\"",
282 | 
283 | "response": {
284 |   "success": true,
285 |   "status": " API is running smoothly ✅",
286 |   "api_info": {
287 |     "name": "Telegram Info API",
288 |     "version": "1.0.0",
289 |     "description": "Advanced Telegram entity information retrieval system",
290 |     "uptime_check": "2025-06-29 14:37:00",
291 |     "bot_status": "Pyrofork Client: connected",
292 |     "features": [
293 |       "User & Bot Information",
294 |       "Channel & Group Details",
295 |       "Account Age Estimation",
296 |       "Data Center Location",
297 |       "Premium Status Detection",
298 |       "Verification Status",
299 |       "Real-time Status Tracking"
300 |     ]
301 |   }
302 | }
303 | 
304 |
305 |
306 |
307 | 308 | 309 |
310 |

The Architect Of This Supreme API

311 |
312 | 313 |

Abir Arafat Chawdhury

314 |

Crafted with passion by @ISmartCoder

315 |

Join the API Updates Channel for best updates!

316 | Join Now 317 |
318 |
319 | 320 | 321 |
322 |

Built with ❤️ by @ISmartCoder

323 |

Join our community at @TheSmartDev

324 |

© 2025 TheSmartDev Info API

325 | 333 |
334 | 335 | 475 | 476 | --------------------------------------------------------------------------------