Create getIntent command
This commit is contained in:
parent
8e05899b0f
commit
64eed85bbc
@ -31,17 +31,51 @@ exports.getIntentCommand = async (req, res) => {
|
|||||||
const intents = await Intent.findAll();
|
const intents = await Intent.findAll();
|
||||||
const intent = intents.find(intent => intent.description === text);
|
const intent = intents.find(intent => intent.description === text);
|
||||||
|
|
||||||
if (command) {
|
if (intent) {
|
||||||
const commandId = await redis.client.xAdd(
|
const commandId = await redis.client.xAdd(
|
||||||
'commands',
|
'commands',
|
||||||
'*',
|
'*',
|
||||||
{
|
{
|
||||||
device_id: device_id,
|
device_id: device_id,
|
||||||
intent: intent.command,
|
command: intent.command,
|
||||||
processed_at: new Date().toISOString(),
|
processed_at: new Date().toISOString(),
|
||||||
source: 'fallback_api',
|
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."});
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user