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>
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
// services/voicePin/resolveVpPinStore.js
|
||
// Resolve a store number to location + voice portal snapshot for /resetvppin.
|
||
|
||
import { logger } from '../../utils/logger.js';
|
||
import { resolveStoreMainNumber } from '../callTest/storeResolver.js';
|
||
|
||
export { parseVpPinStore } from './parseVpPinStore.js';
|
||
|
||
const LOG_SCOPE = 'resetvppin:resolve';
|
||
|
||
async function getWebex() {
|
||
const mod = await import('../../integrations/webex/WebexClient.js');
|
||
return mod.default;
|
||
}
|
||
|
||
/**
|
||
* @param {{ storeNum: string }} parsed
|
||
* @returns {Promise<object>}
|
||
*/
|
||
export async function resolveVpPinStore(parsed) {
|
||
if (!parsed?.storeNum) {
|
||
throw new Error('Invalid store number. Use a 2–4 digit store number.');
|
||
}
|
||
|
||
const store = await resolveStoreMainNumber(parsed.storeNum);
|
||
const { locationId, locationName, storeNum, dialNumber } = store;
|
||
|
||
let voicePortal = null;
|
||
let passcodeRules = null;
|
||
|
||
try {
|
||
const webex = await getWebex();
|
||
[voicePortal, passcodeRules] = await Promise.all([
|
||
webex.request('GET', `telephony/config/locations/${locationId}/voicePortal`),
|
||
webex.request('GET', `telephony/config/locations/${locationId}/voicePortal/passcodeRules`),
|
||
]);
|
||
} catch (err) {
|
||
logger(LOG_SCOPE, `Voice portal fetch failed for location ${locationId}: ${err.message}`, 'warn');
|
||
throw new Error(`Could not load voice portal for store ${storeNum}: ${err.message}`);
|
||
}
|
||
|
||
return {
|
||
storeNum,
|
||
locationId,
|
||
locationName,
|
||
mainNumber: dialNumber,
|
||
voicePortal: {
|
||
name: voicePortal?.name || null,
|
||
extension: voicePortal?.extension || null,
|
||
phoneNumber: voicePortal?.phoneNumber || null,
|
||
language: voicePortal?.language || null,
|
||
raw: voicePortal,
|
||
},
|
||
passcodeRules: passcodeRules || {},
|
||
};
|
||
}
|