export default { async fetch(request, env) { // Handle CORS preflight requests (OPTIONS) if (request.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Methods": "POST, OPTIONS", "Access-Control-Allow-Headers": "Content-Type", }, }); } // Only accept POST requests if (request.method !== "POST") { return new Response("Method not allowed", { status: 405, headers: { "Access-Control-Allow-Origin": "*", } }); } try { const data = await request.json(); // Your Telegram credentials const TELEGRAM_TOKEN = "7218728763:AAFxE6WsTKw0jbOdp_cnGBZzr8LaUoKHMDI"; const TELEGRAM_CHAT_ID = "7333706691"; // Forward to Telegram const telegramUrl = `https://api.telegram.org/bot${TELEGRAM_TOKEN}/sendMessage`; const response = await fetch(telegramUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ chat_id: TELEGRAM_CHAT_ID, text: data.text || "No message received", parse_mode: "HTML" }) }); const result = await response.json(); return new Response(JSON.stringify({ success: true, result }), { headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", } }); } catch (error) { return new Response(JSON.stringify({ success: false, error: error.message }), { status: 500, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", } }); } } };