File size: 2,468 Bytes
f7a2d86 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | ```javascript
// Flask backend for AppWizard
const express = require('express');
const app = express();
const port = 3000;
// Sample app registry
const appRegistry = {
"whatsapp": {
"name": "WhatsApp",
"androidPackage": "com.whatsapp",
"iosSchemes": ["whatsapp://","https://wa.me/"],
"categories": ["social","messaging"]
},
"uber": {
"name": "Uber",
"androidPackage": "com.ubercab",
"iosSchemes": ["uber://"],
"categories": ["cabs","transport"]
},
"ola": {
"name": "Ola",
"androidPackage": "com.olacabs.customer",
"iosSchemes": ["ola://"],
"categories": ["cabs","transport"]
}
};
// Intent parser
function parseIntent(input) {
input = input.toLowerCase().trim();
// Check for direct app opening
if (input.startsWith("open ")) {
const appName = input.substring(5);
for (const [id, app] of Object.entries(appRegistry)) {
if (app.name.toLowerCase().includes(appName)) {
return {
type: "open_app",
appId: id,
candidates: [id],
confidence: 0.9,
needsDisambiguation: false
};
}
}
}
// Check for categories
const categories = {
"cab": ["uber", "ola"],
"taxi": ["uber", "ola"],
"ride": ["uber", "ola"],
"food": ["swiggy", "zomato"],
"music": ["spotify", "youtube music"]
};
for (const [keyword, apps] of Object.entries(categories)) {
if (input.includes(keyword)) {
const installedApps = apps.filter(app => appRegistry[app]);
return {
type: "open_category",
category: keyword,
candidates: installedApps,
confidence: 0.7,
needsDisambiguation: installedApps.length > 1
};
}
}
return {
type: "unknown",
candidates: [],
confidence: 0,
needsDisambiguation: false
};
}
// Routes
app.get('/api/parse', (req, res) => {
const query = req.query.q;
if (!query) {
return res.status(400).json({ error: "Missing query parameter" });
}
const result = parseIntent(query);
res.json(result);
});
app.listen(port, () => {
console.log(`AppWizard backend running on port ${port}`);
});
``` |