const express = require("express"); const app = express(); const PORT = 3000; // ============================== // Ruby Bot — מנוע פנימי // ============================== const conversations = new Map(); function getConversation(sessionId) { if (!conversations.has(sessionId)) { conversations.set(sessionId, []); } return conversations.get(sessionId); } function rubyEngine(message, history) { const text = message.trim().toLowerCase(); if (!text) { return "כתוב לי משהו 🙂"; } if ( text.includes("שלום") || text.includes("היי") || text.includes("הי") || text.includes("אהלן") ) { return "היי! 👋 אני רובי. במה אפשר לעזור לך?"; } if ( text.includes("מי אתה") || text.includes("מי את") || text.includes("מה אתה") ) { return "אני רובי 🤖 — הבוט הפנימי של האתר הזה."; } if ( text.includes("מה אתה יודע") || text.includes("מה אפשר לעשות") ) { return [ "אני רובי 🤖", "", "כרגע אני יודע:", "• לנהל שיחה", "• לזכור את השיחה הנוכחית", "• לזהות שאלות בסיסיות", "• לתת תשובות לפי חוקים", "", "בהמשך אפשר לחבר אותי למנוע AI אמיתי." ].join("\n"); } if ( text.includes("תודה") || text.includes("תודה רבה") ) { return "בשמחה! ❤️"; } if ( text.includes("עזרה") || text.includes("help") ) { return "בטח. ספר לי מה אתה רוצה לעשות ואנסה לעזור."; } if ( text.includes("מה השעה") ) { return `השעה כרגע היא ${new Date().toLocaleTimeString("he-IL")}.`; } if ( text.includes("תאריך") || text.includes("איזה יום") ) { return `היום ${new Date().toLocaleDateString("he-IL")}.`; } if ( text.includes("בדיקה") || text.includes("טסט") ) { return "המערכת עובדת מצוין ✅"; } // תשובה כללית return `קיבלתי את ההודעה שלך: "${message}" אני עדיין בגרסה הראשונה של רובי, ולכן המנוע שלי כרגע בסיסי. אבל התשתית מוכנה — אפשר להפוך אותי למנוע AI מלא בהמשך. 🚀`; } // ============================== // API // ============================== app.use(express.json()); app.post("/api/chat", (req, res) => { try { const { sessionId, message } = req.body; if (!sessionId) { return res.status(400).json({ error: "sessionId חסר" }); } if ( typeof message !== "string" || !message.trim() ) { return res.status(400).json({ error: "הודעה ריקה" }); } const history = getConversation(sessionId); const reply = rubyEngine( message, history ); history.push({ role: "user", content: message, time: Date.now() }); history.push({ role: "assistant", content: reply, time: Date.now() }); // שומרים רק את 50 ההודעות האחרונות if (history.length > 50) { history.splice( 0, history.length - 50 ); } res.json({ reply }); } catch (error) { console.error(error); res.status(500).json({ error: "שגיאת שרת" }); } }); app.delete("/api/chat/:sessionId", (req, res) => { conversations.delete( req.params.sessionId ); res.json({ success: true }); }); // ============================== // האתר כולו // ============================== app.get("/", (req, res) => { res.send(` Ruby Bot

Ruby Bot

העוזר האישי שלך
R
רובי

היי! 👋 אני רובי. במה אפשר לעזור לך?

רובי מקליד...
Hosted & Compiled with HtmlRunner.com
`); }); // ============================== // START // ============================== app.listen(PORT, () => { console.log(""); console.log("🤖 Ruby Bot"); console.log( `🚀 http://localhost:${PORT}` ); console.log(""); });