dragxd commited on
Commit
eaf5eaa
·
verified ·
1 Parent(s): bccf16d

Create bot.py

Browse files
Files changed (1) hide show
  1. bot.py +46 -0
bot.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from telegram import Update
3
+ from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
4
+ import os
5
+
6
+ # Replace with your actual Hugging Face Space backend URL
7
+ BACKEND_URL = "https://dragxd-host.hf.space"
8
+
9
+ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
10
+ await update.message.reply_text("Send /deploy <github_repo_url> to deploy your project!")
11
+
12
+ async def deploy(update: Update, context: ContextTypes.DEFAULT_TYPE):
13
+ if len(context.args) != 1:
14
+ await update.message.reply_text("Usage: /deploy <github_repo_url>")
15
+ return
16
+ github_url = context.args[0]
17
+ user_id = str(update.effective_user.id)
18
+ resp = requests.post(f"{BACKEND_URL}/deploy", json={"github_url": github_url, "user_id": user_id})
19
+ if resp.status_code == 200:
20
+ deploy_id = resp.json()["deploy_id"]
21
+ await update.message.reply_text(f"Deployment started! ID: {deploy_id}\nCheck status with /status {deploy_id}")
22
+ else:
23
+ await update.message.reply_text("Failed to start deployment.")
24
+
25
+ async def status(update: Update, context: ContextTypes.DEFAULT_TYPE):
26
+ if len(context.args) != 1:
27
+ await update.message.reply_text("Usage: /status <deploy_id>")
28
+ return
29
+ deploy_id = context.args[0]
30
+ resp = requests.get(f"{BACKEND_URL}/status/{deploy_id}")
31
+ if resp.status_code == 200:
32
+ data = resp.json()
33
+ await update.message.reply_text(f"Status: {data['status']}\nURL: {data.get('url', 'N/A')}")
34
+ else:
35
+ await update.message.reply_text("Deployment not found.")
36
+
37
+ def main():
38
+ TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN") # Set your bot token as env variable
39
+ app = ApplicationBuilder().token(TOKEN).build()
40
+ app.add_handler(CommandHandler("start", start))
41
+ app.add_handler(CommandHandler("deploy", deploy))
42
+ app.add_handler(CommandHandler("status", status))
43
+ app.run_polling()
44
+
45
+ if __name__ == "__main__":
46
+ main()