netanalyzer/bot/handlers.js
Joseph McQueen 459301cc4d chore: Phase 0 initial hygiene
- Initialize git repository
- Add comprehensive .gitignore (protects .env and secrets)
- Fix package.json (correct main entry, add metadata)
- Expand .env.example with all required variables and comments
- Add README.md with architecture, setup, and commands
- Clean up empty scaffolding directories (logs removed, agents/models marked)
- Backup previous .env file locally

This establishes a safe foundation before further development.
2026-06-24 13:32:37 -04:00

56 lines
No EOL
1.8 KiB
JavaScript

const { getStoreDetail } = require('../integrations/storeDetail');
async function handleStoreCommand(bot, trigger) {
const words = trigger.message.text.trim().split(/\s+/);
const storeNumber = words[1];
if (!storeNumber || isNaN(storeNumber)) {
return bot.say('markdown', 'Usage: `store <number>`\nExample: `store 305`');
}
bot.say('markdown', `🔍 Analyzing Store **${storeNumber}**...`);
try {
const fullReport = await getStoreDetail(storeNumber);
const sections = fullReport.split(/\n\n(?=\*\*)/);
for (let i = 0; i < sections.length; i++) {
const section = sections[i].trim();
if (section) {
await bot.say('markdown', section);
if (i < sections.length - 1) await new Promise(r => setTimeout(r, 400));
}
}
} catch (err) {
console.error('❌ Analysis error:', err);
bot.say('markdown', `❌ Error analyzing store **${storeNumber}**:\n${err.message}`);
}
}
const { getStoreHealth } = require('../integrations/storeHealth');
async function handleAnalyzeCommand(bot, trigger) {
const words = trigger.message.text.trim().split(/\s+/);
const storeNumber = words[1];
if (!storeNumber || isNaN(storeNumber)) {
return bot.say('markdown', 'Usage: `analyze <number>`\nExample: `analyze 305`');
}
bot.say('markdown', `🔍 Running Health Analysis for Store **${storeNumber}**...`);
try {
const health = await getStoreHealth(storeNumber);
if (health && health.summary) {
bot.say('markdown', health.summary); // ← Correct way
} else {
bot.say('markdown', '✅ Analysis completed, but no summary was generated.');
}
} catch (err) {
console.error('❌ Health analysis error:', err);
bot.say('markdown', `❌ Error analyzing store **${storeNumber}**:\n${err.message}`);
}
}
module.exports = { handleStoreCommand, handleAnalyzeCommand };