# app.py import os import asyncio import requests from fastapi import FastAPI from telegram.ext import Application, CommandHandler TELEGRAM_BOT_TOKEN = "7799719627:AAFz7gF74OeajbUqqb4ZJcsJPzal8R8NN3o" # === Region Detection === async def get_real_region(): try: res = requests.get("https://ipapi.co/json/ ", timeout=5) data = res.json() return f"{data.get('country_name', '')}, {data.get('region', '')}" except Exception: return "Unknown location" async def region_command(update, context): await update.message.reply_text(f"📍 This bot is running in: {await get_real_region()}") # === FastAPI App === app = FastAPI() @app.get("/") async def home(): return {"message": "Bot is running. Send /region to Telegram bot."} # === Start Bot and Web Server Together === async def start_bot_and_server(): # Setup Telegram bot application = Application.builder().token(TELEGRAM_BOT_TOKEN).build() application.add_handler(CommandHandler("region", region_command)) await application.initialize() await application.start() # Setup FastAPI server import uvicorn config = uvicorn.Config(app, host="0.0.0.0", port=7860) server = uvicorn.Server(config) await server.serve() if __name__ == "__main__": asyncio.run(start_bot_and_server())