Winhaa commited on
Commit
a37d564
·
verified ·
1 Parent(s): 9b42412

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import logging
3
+ from fastapi import FastAPI
4
+ from fastapi.staticfiles import StaticFiles
5
+ from telegram import Update, WebAppInfo, InlineKeyboardButton, InlineKeyboardMarkup
6
+ from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler
7
+ import uvicorn
8
+ import asyncio
9
+
10
+ # Setup Logging
11
+ logging.basicConfig(level=logging.INFO)
12
+
13
+ app = FastAPI()
14
+
15
+ # Serve Static Files (Frontend)
16
+ app.mount("/static", StaticFiles(directory="static"), name="static")
17
+
18
+ @app.get("/")
19
+ async def read_index():
20
+ return {"message": "HCY Audio System is running. Use /static/index.html to view the app."}
21
+
22
+ # Telegram Bot Logic
23
+ TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
24
+ # Hugging Face Space URL will be used here
25
+ SPACE_URL = os.getenv("SPACE_URL", "https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME")
26
+ WEB_APP_URL = f"{SPACE_URL}/static/index.html"
27
+
28
+ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
29
+ keyboard = [
30
+ [InlineKeyboardButton("Open HCY Audio System", web_app=WebAppInfo(url=WEB_APP_URL))]
31
+ ]
32
+ reply_markup = InlineKeyboardMarkup(keyboard)
33
+ await update.message.reply_text(
34
+ "Welcome to HCY Audio System Clone!\nClick below to open the Mini App.",
35
+ reply_markup=reply_markup
36
+ )
37
+
38
+ async def run_bot():
39
+ if not TOKEN:
40
+ logging.error("TELEGRAM_BOT_TOKEN not found!")
41
+ return
42
+
43
+ application = ApplicationBuilder().token(TOKEN).build()
44
+ application.add_handler(CommandHandler("start", start))
45
+
46
+ await application.initialize()
47
+ await application.start_polling()
48
+ logging.info("Bot is polling...")
49
+
50
+ @app.on_event("startup")
51
+ async def startup_event():
52
+ asyncio.create_task(run_bot())
53
+
54
+ if __name__ == "__main__":
55
+ uvicorn.run(app, host="0.0.0.0", port=7860)