collabSupport/services/jiraPoller/runEnrichment.js
jmcqueen 7dc326c404 Split voice commands into status vs diag and redesign MPP phone output.
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>
2026-07-29 13:55:41 -04:00

77 lines
2.4 KiB
JavaScript

// services/jiraPoller/runEnrichment.js
// Run poller enrichment checks and merge markdown sections.
import { logger } from '../../utils/logger.js';
import { collectPhoneStatus } from '../phoneService.js';
import { collectDeviceStatus } from '../deviceService.js';
import { collectCallReport } from '../callReport/callReportService.js';
import { renderPhoneStatusMarkdown } from '../renderers/phoneStatusRenderer.js';
import { renderAvStatusMarkdown } from '../renderers/avStatusRenderer.js';
import { renderCallReportMarkdown } from '../renderers/callReportRenderer.js';
import { CHECK_IDS } from './enrichmentRules.js';
import { formatEnrichmentBody } from './formatBody.js';
const LOG_SCOPE = 'jira:poller:enrich';
const CHECK_RUNNERS = {
[CHECK_IDS.voicestatus]: async (storeNum) => {
const data = await collectPhoneStatus(storeNum);
return {
title: 'Voice status',
markdown: renderPhoneStatusMarkdown(data, {
storeNum,
detailed: true,
footer: false,
}),
};
},
[CHECK_IDS.avstatus]: async (storeNum) => {
const data = await collectDeviceStatus(storeNum);
return {
title: 'AV status',
markdown: renderAvStatusMarkdown(data, {
storeNum,
detailed: true,
footer: false,
}),
};
},
[CHECK_IDS.callreport]: async (storeNum, opts = {}) => {
const report = await collectCallReport(storeNum, {
dateArg: 'today',
onCdrQueued: ({ runAt, waitMs }) => {
logger(
LOG_SCOPE,
`CDR queued for store ${storeNum} — runs at ${runAt.toISOString()} (~${Math.ceil(waitMs / 1000)}s)`,
'info',
);
},
});
return {
title: 'Call report (today)',
markdown: renderCallReportMarkdown(report, { detail: false }),
};
},
};
/**
* @param {string} storeNum
* @param {string[]} checks ordered check ids
* @param {object} [opts]
* @returns {Promise<{ sections: Array<{title: string, markdown: string}>, bodyMarkdown: string }>}
*/
export async function runEnrichmentChecks(storeNum, checks, opts = {}) {
const sections = [];
for (const checkId of checks) {
const runner = CHECK_RUNNERS[checkId];
if (!runner) {
throw new Error(`Unknown enrichment check: ${checkId}`);
}
const section = await runner(storeNum, opts);
sections.push(section);
}
const bodyMarkdown = formatEnrichmentBody(sections);
return { sections, bodyMarkdown };
}