Files
sitemente/app/api/horus-mc-send/route.ts
T
2026-02-22 16:40:52 +00:00

43 lines
1.1 KiB
TypeScript

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 });
}
}