collabSupport/services/voiceReport/storeContext.js
jmcqueen 1eaabbcee1 Add /voicereport store digest and harden Webex CDR feed handling.
Groups cdr_feed legs by Correlation ID for call-level summaries, fixes report-column field parsing and Docker proxy routing, and adds /calltest post-call Twilio and CDR enrichment.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-24 13:43:11 -04:00

37 lines
1.3 KiB
JavaScript

// services/voiceReport/storeContext.js
// Resolve Webex location + timezone for a store number.
import webex from '../../integrations/webex/WebexClient.js';
import { logger } from '../../utils/logger.js';
import { DISPLAY_TIMEZONE } from '../../utils/time.js';
import { resolveStoreMainNumber } from '../callTest/storeResolver.js';
const LOG_SCOPE = 'voicereport:store';
/**
* @param {string} storeNum
* @returns {Promise<{ storeNum, personId, locationId, locationName, dialNumber, timeZone, email }>}
*/
export async function resolveStoreForVoiceReport(storeNum) {
const base = await resolveStoreMainNumber(storeNum);
let timeZone = DISPLAY_TIMEZONE;
try {
const [profile, location] = await Promise.all([
webex.request('GET', `telephony/config/people/${base.personId}`).catch(() => null),
base.locationId
? webex.request('GET', `telephony/config/locations/${base.locationId}`).catch(() => null)
: null,
]);
timeZone = profile?.timeZone || location?.timeZone || location?.timezone || timeZone;
} catch (err) {
logger(LOG_SCOPE, `Timezone lookup failed for store ${storeNum}: ${err.message}`, 'debug');
}
const padded = String(storeNum).trim().padStart(5, '0');
return {
...base,
timeZone,
email: `ae${padded}@ae.com`,
};
}