Replace /phonestatus follow-ups with /voicestatus, /wanstatus, /phonediag, and /dectdiag; extend /voicediag with relay probes and section-based MPP diagnostics. Co-authored-by: Cursor <cursoragent@cursor.com>
84 lines
2.7 KiB
JavaScript
84 lines
2.7 KiB
JavaScript
// src/commands/phoneDiag.js
|
||
//
|
||
// /phonediag <store> [verbose|debug]
|
||
//
|
||
// MPP desk phone relay diagnostics (CP-7841 etc.): registration,
|
||
// switch LLDP, provisioning history, and formatted issues.
|
||
|
||
import { collectPhoneStatus } from '../services/phoneService.js';
|
||
import { discoverDeskPhones } from '../services/phoneDiscovery.js';
|
||
import { probeAll } from '../services/phoneCollectorService.js';
|
||
import { renderMppPhoneDiagnosticsMarkdown } from '../services/renderers/mppPhoneDiagnosticsRenderer.js';
|
||
import { logger } from '../utils/logger.js';
|
||
|
||
export async function handlePhoneDiag(bot, trigger) {
|
||
const query = trigger.query || {};
|
||
const args = trigger.args || [];
|
||
const storeNum = (args[0]?.trim() || query.storeNum || query.store || query.s || '').trim();
|
||
|
||
const isVerbose = argIncludes(args, 'verbose') || argIncludes(args, 'debug')
|
||
|| query.verbose === 'true' || query.verbose === true
|
||
|| query.debug === 'true' || query.debug === true;
|
||
|
||
if (!storeNum || !/^\d{2,4}$/.test(storeNum)) {
|
||
await bot.say(
|
||
'markdown',
|
||
'Please provide a 2–4 digit store number.\n' +
|
||
'Examples:\n' +
|
||
'- `/phonediag 782`\n' +
|
||
'- `/phonediag 782 verbose`',
|
||
);
|
||
return;
|
||
}
|
||
|
||
if (!process.env.DECT_RELAY_AGENT_TOKEN) {
|
||
await bot.say(
|
||
'markdown',
|
||
'⚠️ Phone relay is not configured on this bot (`DECT_RELAY_AGENT_TOKEN` unset). ' +
|
||
'Set the token and run dect-relay-agent in the data center to enable `/phonediag`.',
|
||
);
|
||
return;
|
||
}
|
||
|
||
logger('phone:diag', `Collecting MPP phone diagnostics for store ${storeNum}`);
|
||
|
||
let phoneData;
|
||
try {
|
||
phoneData = await collectPhoneStatus(storeNum);
|
||
} catch (err) {
|
||
logger('phone:diag', `collectPhoneStatus failed for store ${storeNum}: ${err.message}`, 'error');
|
||
await bot.say('markdown', `❌ Failed to look up store ${storeNum}: ${err.message}`);
|
||
return;
|
||
}
|
||
|
||
const { phones, warnings } = discoverDeskPhones(phoneData || {});
|
||
if (warnings.length > 0) {
|
||
logger(
|
||
'phone:diag',
|
||
`MPP discovery warnings for store ${storeNum}: ${warnings.map((w) => w.reason).join('; ')}`,
|
||
'warn',
|
||
);
|
||
}
|
||
|
||
if (phones.length === 0) {
|
||
await bot.say(
|
||
'markdown',
|
||
`No MPP desk phones discovered on 10.x for store ${storeNum}.`,
|
||
);
|
||
return;
|
||
}
|
||
|
||
await bot.say(
|
||
'markdown',
|
||
`⏳ Probing **${phones.length}** MPP desk phone(s) at store ${storeNum} via relay…`,
|
||
);
|
||
|
||
const results = await probeAll(phones);
|
||
const md = renderMppPhoneDiagnosticsMarkdown(results, { storeNum, verbose: isVerbose });
|
||
await bot.say('markdown', md || 'No data available.');
|
||
}
|
||
|
||
function argIncludes(args, token) {
|
||
const needle = String(token).toLowerCase();
|
||
return (args || []).some((a) => String(a).toLowerCase() === needle);
|
||
}
|