collabSupport/services/voiceDiag/checks/callWaiting.js
jmcqueen d12723d010 Voicediag: store voice standards + port-hygiene checks + apply-all card
Refactor every /voicediag check to declare a top-level `standards`
object so the desired state is legible without reading run() logic
and can drive a documented reference table. Upgrade callForwarding
to error severity, tighten voicemail with three send-to-VM error
paths + a `stop_sending_to_voicemail` remediation, and add a
`disable_hoteling` remediation.

Add a port-hygiene check bucket under services/voiceDiag/checks/port
(portType, portVlan, portPoe, portEnabled) that reuses the phone-
status snapshot to enforce switchport standards. Configurable via
VOICE_STANDARD_PHONE_VLAN (default 102) and VOICE_STANDARD_ENABLED
(kill-switch). Preserve Meraki `portType`/`voiceVlan`/`dataVlan`
through the enrichment chain so the checks have clean data to read.

Add an "apply all N fixes" combined card that shows up when 2+
remediations are available. New confirm_voicediag_all /
cancel_voicediag_all actions run each fix in sequence (readable
audit trail, no per-person write-throttle stacking), accumulate
individual failures into a summary rather than aborting.

Adds regression tests asserting every check exposes .standards,
plus coverage for port checks, kill-switch, and combined-card
iteration. 63 tests in the checks file, 188 total, all green.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-08 14:14:38 -04:00

105 lines
3.3 KiB
JavaScript

// src/services/voiceDiag/checks/callWaiting.js
//
// Detects whether Call Waiting is enabled for the store user. Call
// waiting being *off* is uncommon in a store context — it means a
// second incoming call while the operator is on the phone will get a
// busy tone or hit the busy-forward target instead of showing a
// beep-in on the desk phone.
//
// Endpoint: GET/PUT /v1/people/{personId}/features/callWaiting
// Payload: { enabled: boolean }
// Scope: spark-admin:people_read (GET) + spark-admin:people_write (PUT).
//
// Severity: warn when disabled — we can't tell for sure it's a bug
// (some sites want it off), but for a store phone it's usually
// inadvertent. Remediation: turn call waiting back on.
import { logger } from '../../../utils/logger.js';
import { describeRequester } from '../../../utils/requester.js';
const ENDPOINT = (personId) =>
`people/${personId}/features/callWaiting`;
// Store-line standard: call waiting on. Second-inbound-call beeping
// in is what an operator on a call expects.
export const CALL_WAITING_STANDARDS = Object.freeze({
enabled: true,
});
export const callWaitingCheck = {
id: 'callWaiting',
label: 'Call Waiting',
requires: ['personId'],
scope: 'spark-admin:people_read',
standards: CALL_WAITING_STANDARDS,
async run(ctx) {
const data = await ctx.webex.request('GET', ENDPOINT(ctx.personId));
const enabled = !!data?.enabled;
if (enabled === CALL_WAITING_STANDARDS.enabled) {
return {
status: 'ok',
message: 'Call waiting is on.',
details: { enabled },
remediation: null,
};
}
return {
status: 'warn',
message:
'Call waiting is disabled — a second inbound call will not beep in.',
details: { enabled },
remediation: {
action: 'enable_call_waiting',
title: 'Enable Call Waiting',
summary: `Turn call waiting on for ${ctx.personLabel}.`,
payload: {
personId: ctx.personId,
personLabel: ctx.personLabel,
storeNum: ctx.storeNum,
before: { enabled },
},
},
};
},
remediations: {
async enable_call_waiting(bot, data, requester) {
const { personId, personLabel, storeNum, before } = data;
logger(
'voicediag:audit',
`CONFIRMED enable_call_waiting for ${personLabel} (person=${personId}, store=${storeNum}) ` +
`by ${describeRequester(requester)} — was enabled=${before?.enabled ?? 'unknown'}`,
);
try {
const { default: webex } = await import('../../../integrations/webex/WebexClient.js');
await webex.request('PUT', ENDPOINT(personId), { ...CALL_WAITING_STANDARDS });
} catch (err) {
logger(
'voicediag:audit',
`FAILED enable_call_waiting for ${personLabel}: ${err.message}`,
'error',
);
await bot.say(
'markdown',
`❌ Failed to enable call waiting for **${personLabel}**: ${err.message}`,
);
return;
}
await bot.say(
'markdown',
`✅ Call waiting enabled for **${personLabel}** (store ${storeNum}). ` +
`Re-run \`/voicediag ${storeNum}\` to verify.`,
);
logger(
'voicediag:audit',
`COMPLETED enable_call_waiting for ${personLabel} (store ${storeNum})`,
);
},
},
};