Spaces:
Runtime error
Runtime error
File size: 1,327 Bytes
6d096ba c0ae816 6d096ba 239486c 34d37c4 c0ae816 6d096ba c0ae816 239486c ff71fd7 c0ae816 ff71fd7 c0ae816 ff71fd7 c0ae816 34d37c4 6d096ba 34d37c4 6d096ba c0ae816 34d37c4 c0ae816 34d37c4 c0ae816 34d37c4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | # 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()) |