OHO-8(Entire Voice)
This commit is contained in:
parent
113ccdbc1d
commit
18c57f705f
1 changed files with 38 additions and 2 deletions
|
|
@ -204,10 +204,47 @@ app.get('/api/transactions/recent', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
app.post('/api/transactions/voice', async (req, res) => {
|
||||
try {
|
||||
const { voiceInput } = req.body;
|
||||
if (!voiceInput) {
|
||||
return res.status(400).json({ error: 'No voice input provided' });
|
||||
}
|
||||
// Step 1: Use regex to extract amount
|
||||
const amountMatch = voiceInput.match(/(?:\₹|\$)?(\d+(?:\.\d{1,2})?)/);
|
||||
const amount = amountMatch ? parseFloat(amountMatch[1]) : null;
|
||||
// Step 2: Extract description (rough logic: remove common verbs + amount)
|
||||
const cleaned = voiceInput
|
||||
.toLowerCase()
|
||||
.replace(/(bought|added|paid|spent|for|on)/g, '')
|
||||
.replace(/₹?\d+/, '')
|
||||
.trim();
|
||||
const description = cleaned || 'misc';
|
||||
// Step 3: Predict category using your Flask API
|
||||
const predictRes = await axios.post('http://192.168.1.10:5000/api/predict', {
|
||||
description,
|
||||
});
|
||||
const category = predictRes.data?.category || 'Other';
|
||||
// Step 4: Save to DB
|
||||
const newTransaction = new Transaction({
|
||||
description,
|
||||
amount,
|
||||
category,
|
||||
});
|
||||
await newTransaction.save();
|
||||
res.status(200).json({
|
||||
message: '✅ Voice transaction saved',
|
||||
data: newTransaction,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('❌ Voice transaction error:', err.message);
|
||||
res.status(500).json({ error: 'Server error during voice transaction' });
|
||||
}
|
||||
});
|
||||
// Bank rules (can expand later)
|
||||
const bankRules = [
|
||||
{ name: 'HDFC Bank', email: 'alerts@hdfcbank.net' },
|
||||
// { name: 'ICICI Bank', email: 'alerts@icicibank.com' }, // example expansion
|
||||
{ name: 'ICICI Bank', email: 'alerts@icicibank.com' },
|
||||
];
|
||||
|
||||
// ✅ Gmail fetch function
|
||||
|
|
@ -263,7 +300,6 @@ app.post('/api/sync-gmail', async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
/* ---------- SERVER ---------- */
|
||||
mongoose.connect(process.env.MONGO_URI, {
|
||||
useNewUrlParser: true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue