import { addPhoneNumbersToLocation, findWebexLocation, updateLocationCallingIdentity, } from '../webex/locations.js'; import { findLocationAnnouncements } from '../webex/announcements.js'; import { createStoreAutoAttendant } from '../webex/autoAttendants.js'; import { normalizeStoreUserLicenses } from '../webex/licensing.js'; import { updateUserCallExperience, updateUserCallerId, updateUserExtension, updateUserVoicemailSettings, } from '../webex/users.js'; import { CALLER_ID } from '../constants.js'; import { logger } from '../logger.js'; import { runStep } from './stepRunner.js'; /** * "Migrate store" — finish the cut-over for a store that was previously staged. * Attach the phone number, set caller ID, create the auto-attendant, and clean * up the user's licensing/voicemail. */ export async function migrateStoreLocation(bot, locationInfo, userInfo) { logger.info(`Migrating location ${locationInfo.name}`); const matches = await findWebexLocation(locationInfo.name); if (!matches.length) { throw new Error( `No existing Webex location found for ${locationInfo.name}. Did you stage first?`, ); } const location = matches[0]; await runStep(bot, 'Added phone numbers to location', () => addPhoneNumbersToLocation(location, locationInfo.phoneNumber), ); await runStep(bot, 'Updated location Webex Calling Details', () => updateLocationCallingIdentity(location, locationInfo.phoneNumber), ); await runStep(bot, 'Updated user extension', () => updateUserExtension(userInfo, locationInfo.extension), ); await runStep(bot, 'Updated user call application experience', () => updateUserCallExperience(userInfo), ); await runStep(bot, 'Updated user Caller ID Information', () => updateUserCallerId(userInfo, locationInfo.extension, locationInfo.phoneNumber, { locationFallbackNumber: CALLER_ID.locationFallbackNumber, customExternalCallerIdName: CALLER_ID.customExternalCallerIdName, }), ); await runStep(bot, 'Updated user voicemail settings', () => updateUserVoicemailSettings(userInfo), ); const announcements = await runStep(bot, 'Located store announcement', () => findLocationAnnouncements(location), ); if (announcements && announcements[0]) { location.announcementId = announcements[0].id; await runStep(bot, 'Created auto attendant', () => createStoreAutoAttendant(location, locationInfo), ); } else { bot.say( 'markdown', "
Skipping auto attendant: no location announcement found.", ); } await runStep(bot, 'Fixed Licenses', () => normalizeStoreUserLicenses(userInfo)); bot.say('Migration Complete!'); return location; }