diff --git a/app/api/horus-mc-response/route.ts b/app/api/horus-mc-response/route.ts new file mode 100644 index 0000000..4776bff --- /dev/null +++ b/app/api/horus-mc-response/route.ts @@ -0,0 +1,24 @@ +import { NextResponse } from "next/server"; +import fs from "fs"; + +const RESPONSE_FILE = "/tmp/horus-mc-response.txt"; + +export async function GET() { + try { + // Check if there's a response file + if (fs.existsSync(RESPONSE_FILE)) { + const response = fs.readFileSync(RESPONSE_FILE, "utf-8").trim(); + + if (response) { + // Clear the file after reading + fs.writeFileSync(RESPONSE_FILE, ""); + return NextResponse.json({ response }); + } + } + + return NextResponse.json({ response: null }); + } catch (error) { + console.error("Error:", error); + return NextResponse.json({ response: null }); + } +} diff --git a/app/api/horus-mc-send/route.ts b/app/api/horus-mc-send/route.ts new file mode 100644 index 0000000..7dcfbae --- /dev/null +++ b/app/api/horus-mc-send/route.ts @@ -0,0 +1,42 @@ +import { NextResponse } from "next/server"; + +// Store messages in temp file +const QUEUE_FILE = "/tmp/horus-mc-queue.json"; + +async function sendToTelegram(text: string) { + const token = process.env.TELEGRAM_BOT_TOKEN; + if (!token) { + console.log("No Telegram token"); + return null; + } + + // Send to Haitham via Telegram + const res = await fetch(`https://api.telegram.org/bot${token}/sendMessage`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + chat_id: "382315644", + text: `💬 MC Chat:\n${text}`, + }), + }); + + return res.json(); +} + +export async function POST(request: Request) { + try { + const { message } = await request.json(); + + if (!message) { + return NextResponse.json({ error: "Message required" }, { status: 400 }); + } + + // Forward to Telegram + await sendToTelegram(message); + + return NextResponse.json({ status: "sent" }); + } catch (error) { + console.error("Error:", error); + return NextResponse.json({ error: "Failed" }, { status: 500 }); + } +} diff --git a/components/mission-control/HorusChat.tsx b/components/mission-control/HorusChat.tsx index c4b09fc..4ca0799 100644 --- a/components/mission-control/HorusChat.tsx +++ b/components/mission-control/HorusChat.tsx @@ -10,7 +10,7 @@ interface Message { timestamp: number; } -export default function VoiceChat() { +export default function HorusChat() { const [input, setInput] = useState(""); const [messages, setMessages] = useState([ { @@ -27,6 +27,34 @@ export default function VoiceChat() { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages]); + // Poll for responses from Horus (Telegram) + useEffect(() => { + let pollInterval: NodeJS.Timeout; + + if (isProcessing) { + pollInterval = setInterval(async () => { + try { + const res = await fetch("/api/horus-mc-response"); + const data = await res.json(); + + if (data.response) { + setMessages(prev => [...prev, { + id: `horus_${Date.now()}`, + role: "assistant", + content: data.response, + timestamp: Date.now(), + }]); + setIsProcessing(false); + } + } catch (e) { + console.error("Poll error:", e); + } + }, 3000); + } + + return () => clearInterval(pollInterval); + }, [isProcessing]); + const handleSend = async () => { if (!input.trim() || isProcessing) return; @@ -42,35 +70,22 @@ export default function VoiceChat() { setIsProcessing(true); try { - // Send to SiteMente AI agent - const res = await fetch("/api/chat/agent", { + // Send to Horus via Telegram + await fetch("/api/horus-mc-send", { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - message: userMessage.content, - locale: "es" - }), + body: JSON.stringify({ message: userMessage.content }), }); - - const data = await res.json(); - const botMessage: Message = { - id: `bot_${Date.now()}`, - role: "assistant", - content: data.response || "Entendido.", - timestamp: Date.now(), - }; - - setMessages(prev => [...prev, botMessage]); + // Will receive response via polling } catch (e) { - console.error("Chat error:", e); + console.error("Send error:", e); setMessages(prev => [...prev, { id: `error_${Date.now()}`, role: "assistant", content: "Error de conexión. Prueba en Telegram.", timestamp: Date.now(), }]); - } finally { setIsProcessing(false); } }; @@ -87,8 +102,8 @@ export default function VoiceChat() { {/* Header */}
- 💬 - Horus Chat + 👁️ + Horus
{isProcessing && ( @@ -129,7 +144,7 @@ export default function VoiceChat() { value={input} onChange={(e) => setInput(e.target.value)} onKeyPress={handleKeyPress} - placeholder="Escribe un mensaje..." + placeholder="Escribe a Horus..." className="flex-1 bg-white/5 border border-white/10 rounded-lg px-4 py-2 text-sm text-white placeholder:text-white/40 focus:outline-none focus:border-brand-pink" disabled={isProcessing} /> @@ -142,7 +157,7 @@ export default function VoiceChat() {

- O chatea directamente en Telegram + Respondo en Telegram - ¡Escríbeme ahí también!