Create getIntent command

This commit is contained in:
Apher 2026-06-28 20:04:55 +00:00
parent 8e05899b0f
commit 64eed85bbc

View File

@ -31,17 +31,51 @@ exports.getIntentCommand = async (req, res) => {
const intents = await Intent.findAll();
const intent = intents.find(intent => intent.description === text);
if (command) {
if (intent) {
const commandId = await redis.client.xAdd(
'commands',
'*',
{
device_id: device_id,
intent: intent.command,
command: intent.command,
processed_at: new Date().toISOString(),
source: 'fallback_api',
}
);
console.log(`Intent matched and published to stream: ${commandId}`);
return res.json({
success: true,
intent: intent.description,
command: intent.command
});
} else {
const errorId = await redis.client.xAdd(
'commands',
'*',
{
device_id: device_id,
intent: 'error',
command: 'intent_not_found',
processed_at: new Date().toISOString(),
source: 'fallback_api'
}
);
console.log(`No intent match, error published: ${errorId}`);
return res.status(400).json({
success: false,
error: 'intent_not_found',
message: `Could not understand: "${text}"`,
stream_id: errorId,
source: 'fallback_api',
});
}
}
} catch (err) {
console.error("getIntentCommand error:", err);
return res.status(500).send({message: err.message || "Internal server error."});
}
};