Fix undefined variables in redis stream

This commit is contained in:
Apher Fox 2026-07-02 08:30:30 +00:00
parent 2d84f16e8a
commit 39f6c03787

View File

@ -22,7 +22,6 @@ exports.getAllIntents = async (req, res) => {
exports.getIntentCommand = async (req, res) => { exports.getIntentCommand = async (req, res) => {
try { try {
const {text, device_id} = req.body; const {text, device_id} = req.body;
console.log(req.body, text, device_id);
if (!text || !device_id) { if (!text || !device_id) {
return res.status(400).json({ return res.status(400).json({
@ -34,18 +33,15 @@ exports.getIntentCommand = async (req, res) => {
await redis.client.connect().catch(console.error) await redis.client.connect().catch(console.error)
const intents = await Intent.findAll(); const intent = await Intent.findOne({ where: { description: req.body.text } });
const intent = intents.find(obj => obj.description === text);
console.log(intents, intent);
if (intent) { if (intent) {
const commandId = await redis.client.xAdd( const commandId = await redis.client.xAdd(
'communication', 'communication',
'*', '*',
{ {
device_id: config.DEVICE_ID, device_id: device_id,
command: intent.command, command: intent.dataValues.command,
processed_at: new Date().toISOString(), processed_at: new Date().toISOString(),
source: config.DEVICE_ID, source: config.DEVICE_ID,
} }
@ -66,7 +62,6 @@ exports.getIntentCommand = async (req, res) => {
'*', '*',
{ {
device_id: device_id, device_id: device_id,
intent: 'error',
command: 'intent_not_found', command: 'intent_not_found',
processed_at: new Date().toISOString(), processed_at: new Date().toISOString(),
source: config.DEVICE_ID source: config.DEVICE_ID