-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtelegram_bot.py
More file actions
106 lines (71 loc) · 2.3 KB
/
telegram_bot.py
File metadata and controls
106 lines (71 loc) · 2.3 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import asyncio
import subprocess
from dotenv import load_dotenv
from telegram import Update
from telegram.ext import (
ApplicationBuilder,
CommandHandler,
ContextTypes
)
load_dotenv()
TOKEN = os.getenv("TELEGRAM_TOKEN")
# ---------------- START COMMAND ----------------
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
message = (
"🚀 SitePilot is ready\n\n"
"Use:\n"
"/pilot <describe website change>\n\n"
"Example:\n"
"/pilot create dark mode toggle button"
)
await update.message.reply_text(message)
# ---------------- PILOT COMMAND ----------------
async def pilot(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not context.args:
await update.message.reply_text(
"Usage:\n/pilot <describe website change>"
)
return
prompt = " ".join(context.args)
await update.message.reply_text("🧠 SitePilot thinking...")
try:
process = await asyncio.create_subprocess_exec(
"python",
"mcp_server.py",
prompt,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = await process.communicate()
if process.returncode != 0:
await update.message.reply_text(
f"❌ Error:\n{stderr.decode()}"
)
return
await update.message.reply_text(
"🚀 Website updated and deployed successfully!"
)
except Exception as e:
await update.message.reply_text(
f"⚠️ Unexpected error:\n{str(e)}"
)
# ---------------- STATUS COMMAND ----------------
async def status(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(
"✅ SitePilot is running.\n"
"AI website maintenance ready."
)
# ---------------- MAIN ----------------
def main():
if not TOKEN:
print("TELEGRAM_TOKEN missing in .env")
return
app = ApplicationBuilder().token(TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("pilot", pilot))
app.add_handler(CommandHandler("status", status))
print("🚀 Telegram bot running")
app.run_polling()
if __name__ == "__main__":
main()