// src/commands/testDevicesByModel.js import { logger } from '../utils/logger.js'; import { fetchAllPages } from '../integrations/meraki/client.js'; // or use direct axios if you prefer import botClient from '../integrations/webex/BotClient.js'; export async function handleTestDevicesByModel(bot, trigger) { const roomId = trigger.roomId || trigger.message?.roomId; if (!roomId) return; await bot.say('markdown', '🔄 Testing **Devices Overview by Model** endpoint...'); try { const orgId = process.env.MERAKI_ORG_ID; logger('test-by-model', `Calling /organizations/${orgId}/devices/overview/byModel`); // This endpoint does not support pagination — it returns all models in one call const response = await fetchAllPages(`/organizations/${orgId}/devices/overview/byModel`); // or direct axios.get const counts = response.counts || response || []; logger('test-by-model', `Received counts for ${counts.length} models`); let reply = `**Devices Overview by Model**\n\n`; reply += `Total models returned: ${counts.length}\n\n`; let table = '| Model | Count |\n|-------|-------|\n'; counts.forEach(item => { table += `| ${item.model || '—'} | ${item.total || 0} |\n`; }); reply += table; await bot.say('markdown', reply); // Optional: Also send as CSV for easy download let csv = 'Model,Count\n'; counts.forEach(item => { csv += `"${item.model || '—'}",${item.total || 0}\n`; }); const buffer = Buffer.from(csv, 'utf8'); await botClient.sendWithAttachment( roomId, buffer, `Devices_By_Model_${new Date().toISOString().slice(0,10)}.csv`, 'text/csv', '📊 Devices Overview by Model CSV attached' ); } catch (err) { logger('test-by-model', `Error: ${err.message}`, 'error'); await bot.say('markdown', `❌ Error calling overview by model: ${err.message}`); } }