Chat-only commands reset voicemail mailbox and voice portal passcodes via telephony_config_write, with extension lookup and unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
709 B
JavaScript
25 lines
709 B
JavaScript
// services/voicePin/parseVmPinTarget.js
|
|
|
|
const STORE_RE = /^\d{2,4}$/;
|
|
const EXTENSION_RE = /^\d{5}$/;
|
|
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/i;
|
|
|
|
/**
|
|
* @param {string} raw
|
|
* @returns {{ kind: 'email', email: string } | { kind: 'store', storeNum: string } | { kind: 'extension', extension: string } | null}
|
|
*/
|
|
export function parseVmPinTarget(raw) {
|
|
const token = String(raw || '').trim();
|
|
if (!token) return null;
|
|
|
|
if (EMAIL_RE.test(token)) {
|
|
return { kind: 'email', email: token.toLowerCase() };
|
|
}
|
|
if (STORE_RE.test(token)) {
|
|
return { kind: 'store', storeNum: token };
|
|
}
|
|
if (EXTENSION_RE.test(token)) {
|
|
return { kind: 'extension', extension: token };
|
|
}
|
|
return null;
|
|
}
|