Send to stream when intent is created
This commit is contained in:
parent
39f6c03787
commit
6dc037e4aa
@ -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)
|
await redis.client.connect().catch(console.error)
|
||||||
|
|
||||||
@ -92,10 +92,14 @@ exports.getIntentCommand = async (req, res) => {
|
|||||||
// Create intent
|
// Create intent
|
||||||
exports.createIntent = async (req, res) => {
|
exports.createIntent = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {command, description, type} = req.body;
|
const {command, description, type, device_id} = req.body;
|
||||||
|
|
||||||
if (!command || !description || !type) {
|
console.log(`\n[Backend Intents] Creating intent.`)
|
||||||
return res.status(400).send({message: "Missing required fields: command, description, type"});
|
|
||||||
|
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({
|
const intent = await Intent.create({
|
||||||
@ -104,7 +108,22 @@ exports.createIntent = async (req, res) => {
|
|||||||
type
|
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) {
|
} catch (err) {
|
||||||
console.error("createIntent error:", err);
|
console.error("createIntent error:", err);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user