wbxcallprov/src/commands/attachmentActions.js
jmcqueen 5dce057ce7
Some checks are pending
CI / verify (push) Waiting to run
Add /provisionDect + create DECT network in /finalizeStore
New /provisionDect slash command manages DECT basestations and handsets
for a store via a single card: multi-select checkbox list doubles as
the display, MACs render as AA:BB:CC:DD:EE:FF, Add/Remove sit
side-by-side per section, and every removal goes through an explicit
confirm card. Handsets always auto-pair (no bind-to-basestation input)
so they roam.

/finalizeStore now idempotently creates the "Store XXXX" DECT network
(DBS-210) with the per-store default access code, so new stores are
DECT-ready the moment finalize completes. Location-scoped lookup
(findDectNetworkInLocation) handles both the finalize idempotency
check and the /provisionDect fallback for freshly-created empty
networks. Non-critical: a store can still go live if the DECT step
fails, and /provisionDect keeps a recovery "create network" prompt
for legacy stores.

Pure-logic helpers (generateDectAccessCode, MAC normalize/format/
display, dectNetworkName) are unit-tested via node:test.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-07 07:29:21 -04:00

66 lines
2.6 KiB
JavaScript

import { logger } from '../logger.js';
import { stageStoreLocation } from '../flows/stageStore.js';
import { finalizeStoreLocation } from '../flows/finalizeStore.js';
import { getWebexDeviceDetail } from '../webex/devices.js';
import { handleDectAction } from './dectActions.js';
async function runFlow(bot, trigger, verb, fn) {
const { storeInfo, userInfo } = trigger.attachmentAction.inputs;
bot.censor(trigger.attachmentAction.messageId);
bot.say(`${verb} ${storeInfo.name}.`);
try {
await fn(bot, storeInfo, userInfo);
bot.say(`Finished ${verb.toLowerCase()} ${storeInfo.name}.`);
} catch (error) {
logger.error(`${verb} failed for ${storeInfo?.name}:`, error);
bot.say(`Error ${verb.toLowerCase()} ${storeInfo?.name}: ${error.message}`);
}
}
async function showDevices(bot, trigger) {
const deviceIds = (trigger.attachmentAction.inputs.devices ?? '').split(',').filter(Boolean);
for (const deviceId of deviceIds) {
try {
const detail = await getWebexDeviceDetail(deviceId);
bot.say('markdown', `\`\`\` json\n${JSON.stringify(detail, null, 2)}\n\`\`\`\n`);
} catch (error) {
logger.error('Failed to fetch device detail:', error);
bot.say(`Failed to fetch device ${deviceId}: ${error.message}`);
}
}
}
export function register(framework) {
framework.on('attachmentAction', async (bot, trigger) => {
logger.debug('attachmentAction', JSON.stringify(trigger));
const action = trigger.attachmentAction.inputs.action;
// DECT flow has its own sub-dispatcher.
if (typeof action === 'string' && action.startsWith('dect-')) {
await handleDectAction(bot, trigger, action);
return;
}
switch (action) {
case 'stageStore':
await runFlow(bot, trigger, 'Staging', stageStoreLocation);
break;
case 'finalizeStore':
await runFlow(bot, trigger, 'Finalizing', finalizeStoreLocation);
break;
case 'showDevice':
await showDevices(bot, trigger);
break;
case 'deleteCard':
bot.censor(trigger.attachmentAction.messageId);
break;
default:
if (trigger.attachmentAction.inputs.responseTo === 'badInfo') {
bot.say(
'If information is not correct, please check Store Info Web or contact the administrator.',
);
}
break;
}
});
}