diff --git a/src/controllers/intent.controller.js b/src/controllers/intent.controller.js index a5d0a10..6b5b7ed 100644 --- a/src/controllers/intent.controller.js +++ b/src/controllers/intent.controller.js @@ -4,7 +4,7 @@ const redis = models.redis; const {sequelize, Sequelize} = db; const Intent = db.intent; -exports.getIntents = async (req, res) => { +exports.getAllIntents = async (req, res) => { try { const intents = await Intent.findAll(); @@ -14,4 +14,34 @@ exports.getIntents = async (req, res) => { return res.status(500).send({message: err.message || "Internal server error."}); } -}; \ No newline at end of file +}; + +exports.getIntentCommand = async (req, res) => { + try { + const {text, device_id} = req.body; + + if (!text || !device_id) { + return res.status(400).json({ + error: 'Missing required fields: text, device_id', + }); + } + + console.log(`\n[FALLBACK API] Processing intent.`); + + const intents = await Intent.findAll(); + const intent = intents.find(intent => intent.description === text); + + if (command) { + const commandId = await redis.client.xAdd( + 'commands', + '*', + { + device_id: device_id, + intent: intent.command, + processed_at: new Date().toISOString(), + source: 'fallback_api', + } + ); + } + } +} \ No newline at end of file diff --git a/src/routes/intent.routes.js b/src/routes/intent.routes.js index 48bdb9e..3228941 100644 --- a/src/routes/intent.routes.js +++ b/src/routes/intent.routes.js @@ -13,6 +13,6 @@ const controller = require("../controllers/intent.controller"); // Intent routes // Get all intents -router.get("/", /*[authJwt.verifyToken, authJwt.isAdmin],*/ controller.getIntents); +router.get("/", /*[authJwt.verifyToken, authJwt.isAdmin],*/ controller.getAllIntents); module.exports = router; \ No newline at end of file