collabSupport/services/voicePin/resolveVpPinStore.js
jmcqueen 2ec2b7a486 Add /resetvmpin and /resetvppin with confirmation cards for Webex PIN resets.
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>
2026-07-31 16:34:09 -04:00

56 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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 24 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 || {},
};
}