Connect Horus Chat to Telegram (Horus)

This commit is contained in:
root
2026-02-22 16:40:52 +00:00
parent 98334847dc
commit d97e88a8c1
3 changed files with 104 additions and 23 deletions
+24
View File
@@ -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 });
}
}
+42
View File
@@ -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 });
}
}