Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
# app.py
|
| 2 |
|
| 3 |
import os
|
| 4 |
-
import threading
|
| 5 |
import asyncio
|
| 6 |
import requests
|
| 7 |
-
from
|
| 8 |
from telegram.ext import Application, CommandHandler
|
| 9 |
|
| 10 |
TELEGRAM_BOT_TOKEN = "7799719627:AAFz7gF74OeajbUqqb4ZJcsJPzal8R8NN3o"
|
|
@@ -23,29 +22,29 @@ async def region_command(update, context):
|
|
| 23 |
await update.message.reply_text(f"📍 This bot is running in: {await get_real_region()}")
|
| 24 |
|
| 25 |
|
| 26 |
-
# ===
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
application.add_handler(CommandHandler("region", region_command))
|
| 30 |
-
await application.run_polling()
|
| 31 |
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
def run_bot_in_thread():
|
| 34 |
-
asyncio.run(start_bot())
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
| 45 |
-
|
| 46 |
-
bot_thread = threading.Thread(target=run_bot_in_thread)
|
| 47 |
-
bot_thread.daemon = True
|
| 48 |
-
bot_thread.start()
|
| 49 |
-
|
| 50 |
-
# Run Flask on main thread
|
| 51 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
# app.py
|
| 2 |
|
| 3 |
import os
|
|
|
|
| 4 |
import asyncio
|
| 5 |
import requests
|
| 6 |
+
from fastapi import FastAPI
|
| 7 |
from telegram.ext import Application, CommandHandler
|
| 8 |
|
| 9 |
TELEGRAM_BOT_TOKEN = "7799719627:AAFz7gF74OeajbUqqb4ZJcsJPzal8R8NN3o"
|
|
|
|
| 22 |
await update.message.reply_text(f"📍 This bot is running in: {await get_real_region()}")
|
| 23 |
|
| 24 |
|
| 25 |
+
# === FastAPI App ===
|
| 26 |
+
app = FastAPI()
|
| 27 |
+
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
@app.get("/")
|
| 30 |
+
async def home():
|
| 31 |
+
return {"message": "Bot is running. Send /region to Telegram bot."}
|
| 32 |
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# === Start Bot and Web Server Together ===
|
| 35 |
+
async def start_bot_and_server():
|
| 36 |
+
# Setup Telegram bot
|
| 37 |
+
application = Application.builder().token(TELEGRAM_BOT_TOKEN).build()
|
| 38 |
+
application.add_handler(CommandHandler("region", region_command))
|
| 39 |
+
await application.initialize()
|
| 40 |
+
await application.start()
|
| 41 |
|
| 42 |
+
# Setup FastAPI server
|
| 43 |
+
import uvicorn
|
| 44 |
+
config = uvicorn.Config(app, host="0.0.0.0", port=7860)
|
| 45 |
+
server = uvicorn.Server(config)
|
| 46 |
+
await server.serve()
|
| 47 |
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|
| 50 |
+
asyncio.run(start_bot_and_server())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|