File size: 1,168 Bytes
c0ae816
 
239486c
c0ae816
 
 
 
 
 
239486c
ff71fd7
 
 
c0ae816
ff71fd7
c0ae816
 
 
ff71fd7
c0ae816
 
ff71fd7
 
 
 
c0ae816
 
 
 
 
 
ff71fd7
c0ae816
 
 
ff71fd7
 
 
 
c0ae816
ff71fd7
 
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
import os
import threading
import requests
from flask import Flask
from telegram.ext import Application, CommandHandler

TELEGRAM_BOT_TOKEN = "7799719627:AAFz7gF74OeajbUqqb4ZJcsJPzal8R8NN3o"

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()}")


def start_telegram_bot():
    app = Application.builder().token(TELEGRAM_BOT_TOKEN).build()
    app.add_handler(CommandHandler("region", region_command))
    app.run_polling()


# === Flask Web App (port 7860) ===
app = Flask(__name__)
@app.route("/")
def home():
    return "Bot is running. Send /region to Telegram bot."


if __name__ == "__main__":
    # Start Telegram bot in background
    bot_thread = threading.Thread(target=start_telegram_bot)
    bot_thread.daemon = True
    bot_thread.start()

    # Run Flask on main thread
    app.run(host="0.0.0.0", port=7860)