collabSupport/services/callTest/parseArgs.js
Joseph McQueen 7aa8c37d1d Add Twilio /calltest for store and direct-dial voice path testing.
Enables outbound PSTN probes via TwiML webhooks with Webex result cards, status polling, and optional store CDR enrichment.
2026-07-23 17:59:10 -04:00

43 lines
1.4 KiB
JavaScript

// services/callTest/parseArgs.js
import { isStoreNumberToken, normalizeE164 } from './config.js';
/**
* Parse /calltest args into a command descriptor.
* @returns {{ kind: 'usage'|'status'|'store'|'dial', storeNum?: string, dial?: string, dialOverride?: string|null, testId?: string }}
*/
export function parseCallTestArgs(args = []) {
const tokens = (args || []).map((a) => String(a).trim()).filter(Boolean);
if (!tokens.length) return { kind: 'usage' };
const first = tokens[0].toLowerCase();
if (first === 'status') {
const testId = tokens[1];
return testId ? { kind: 'status', testId } : { kind: 'usage' };
}
if (first === 'store') {
const storeNum = tokens[1];
if (!storeNum || !isStoreNumberToken(storeNum)) return { kind: 'usage' };
const override = tokens[2] ? normalizeE164(tokens[2]) : null;
if (tokens[2] && !override) return { kind: 'usage' };
return { kind: 'store', storeNum, dialOverride: override };
}
if (first === 'dial') {
const dial = normalizeE164(tokens[1]);
return dial ? { kind: 'dial', dial } : { kind: 'usage' };
}
if (isStoreNumberToken(first)) {
const override = tokens[1] ? normalizeE164(tokens[1]) : null;
if (tokens[1] && !override) return { kind: 'usage' };
return { kind: 'store', storeNum: first, dialOverride: override };
}
const dial = normalizeE164(first);
if (dial) return { kind: 'dial', dial };
return { kind: 'usage' };
}