const Framework = require('webex-node-bot-framework'); const config = require('./config'); const { startWebSocketServer } = require('./services/websocket'); const { handleStoreCommand, handleAnalyzeCommand } = require('./bot/handlers'); const framework = new Framework({ token: config.webex.token, removeWebhooksOnStart: true, logLevel: 'debug' }); console.log('🚀 Starting NetAnalyzer Framework...'); // Register command handlers framework.hears(/store/i, handleStoreCommand, '**store ** - Analyze a store'); framework.hears(/analyze/i, handleAnalyzeCommand, '**analyze ** - High-level store health check'); // Catch-all handler for debugging (lowest priority) framework.hears(/.*/, (bot, trigger) => { // Only log and respond if this pattern matched if (trigger.match && trigger.match[0].length > 0) { const text = trigger.message.text.toLowerCase(); // Skip if message contains known commands already handled if (!text.includes('store') && !text.includes('analyze')) { console.log('📨 Received message:', trigger.message.text); bot.say('I heard: ' + trigger.message.text + '\nTry: `store ` or `analyze ` for store analysis'); } } }, 99999); // lowest priority // Framework events framework.on('initialized', () => { console.log('✅ Framework initialized and connected via WebSocket!'); }); framework.on('spawn', (bot, id, addedBy) => { console.log(`🟢 Bot spawned in room: ${bot.room.title || 'Unknown'}`); if (addedBy) { bot.say('NetAnalyzer is ready! Try `store ` or `analyze `'); } }); // Start framework and WebSocket server sequentially framework.start().then(() => { console.log('WebSocket server for remote agent starting...'); startWebSocketServer(); }).catch(err => { console.error('❌ Error starting framework:', err); process.exit(1); });