Send to stream when intent is created

This commit is contained in:
Apher Fox 2026-07-02 08:57:42 +00:00
parent 39f6c03787
commit 6dc037e4aa

View File

@ -29,7 +29,7 @@ exports.getIntentCommand = async (req, res) => {
});
}
console.log(`\n[FALLBACK API] Processing intent.`);
console.log(`\n[Backend Intents] Processing intent.`);
await redis.client.connect().catch(console.error)
@ -92,10 +92,14 @@ exports.getIntentCommand = async (req, res) => {
// Create intent
exports.createIntent = async (req, res) => {
try {
const {command, description, type} = req.body;
const {command, description, type, device_id} = req.body;
if (!command || !description || !type) {
return res.status(400).send({message: "Missing required fields: command, description, type"});
console.log(`\n[Backend Intents] Creating intent.`)
await redis.client.connect().catch(console.error);
if (!command || !description || !type || !device_id) {
return res.status(400).send({message: "Missing required fields: command, description, type, device_id"});
}
const intent = await Intent.create({
@ -104,7 +108,22 @@ exports.createIntent = async (req, res) => {
type
});
return res.status(201).send({message: "Intent created successfully.", intent});
await redis.client.connect().catch(console.error);
const commandId = await redis.client.xAdd(
'communication',
'*',
{
device_id: device_id,
command: "CREATE_INTENT",
processed_at: new Date().toISOString(),
source: config.DEVICE_ID,
}
);
await redis.client.quit();
return res.status(201).send({message: "Intent created successfully.", intent, commandId});
} catch (err) {
console.error("createIntent error:", err);