import { logger } from '../logger.js'; import { findWebexLocation } from '../webex/locations.js'; import { dectNetworkName, generateDectAccessCode, getDectProvisioningStatus, } from '../webex/dect.js'; import { dectCreateNetworkCard, dectManagementCard } from '../cards/dectCards.js'; import { parseStoreNumber } from './helpers.js'; // /provisionDect does NOT require the remote agent — every operation is // against public Webex Calling APIs, which the bot reaches directly. export function register(framework) { framework.hears( /\/provisiondect/i, async (bot, trigger) => { logger.info(`${trigger.person.displayName} ran the provisionDect command.`); const storeNumber = parseStoreNumber(trigger); if (!storeNumber) { bot.say('Usage: `/provisionDect ` — e.g. `/provisionDect 499`'); return; } try { const status = await getDectProvisioningStatus(storeNumber); if (status.network) { bot.sendCard( dectManagementCard(storeNumber, status), 'Please use another client', ); return; } // No network yet — need the store's Webex location to create in. const matches = await findWebexLocation(dectNetworkName(storeNumber)); if (!matches.length) { bot.say( 'markdown', `No Webex location found for **${dectNetworkName(storeNumber)}**. ` + `Run \`/stageStore ${storeNumber}\` first.`, ); return; } const location = matches[0]; bot.sendCard( dectCreateNetworkCard(storeNumber, { locationId: location.id, locationName: location.name, suggestedAccessCode: generateDectAccessCode(storeNumber), }), 'Please use another client', ); } catch (error) { logger.error('provisionDect command failed:', error); bot.say( 'markdown', `Error running /provisionDect:\n\`\`\`\n${error.message}\n\`\`\``, ); } }, '**/provisionDect** - Add or remove DECT basestations and handsets for a store. New stores get their DECT network created by /finalizeStore; this command offers a recovery-create prompt if the network is missing.', ); }