wbxcallprov/src/commands/attachmentActions.js
jmcqueen 93b060bc8b Modernize bot to Node.js 22 with modular architecture and remote SIW agent
- Refactor monolithic index.js (2646 lines) into src/{webex,integrations,
  cards,flows,commands,services} modules; replace node-fetch/form-data
  with native fetch/FormData; move all secrets to .env via dotenv
- Add dockerized remote SIW agent (docker/remote-agent/) with cross-arch
  buildx packaging (arm64 Mac -> linux/amd64), idempotent install.sh
  deploy bundle, and docker-free ZIP inspector for arch verification
- Bot hosts a WebSocket server; agent proxies SIW requests with a
  per-request insecure:true flag, replacing the process-wide
  NODE_TLS_REJECT_UNAUTHORIZED bypass
- Add ESLint flat config + Prettier, rewrite Dockerfile as non-root
  multi-stage node:22-alpine build, README covering setup / deploy /
  remote agent workflow
- Fix parseStoreArg to read trigger.prompt correctly (was indexing past
  the framework's post-match slice); register /help as regex (string
  matcher only compares the first token); switch catch-all to /.+/
  (previous /.*/gim was stateful due to the g flag); remove
  /fixDisplayNames command and its flow/card

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 14:48:51 -04:00

63 lines
2.5 KiB
JavaScript

import { logger } from '../logger.js';
import { buildStoreLocation } from '../flows/buildStore.js';
import { stageStoreLocation } from '../flows/stageStore.js';
import { migrateStoreLocation } from '../flows/migrateStore.js';
import { getWebexDeviceDetail } from '../webex/devices.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;
switch (action) {
case 'buildStore':
await runFlow(bot, trigger, 'Building', buildStoreLocation);
break;
case 'stageStore':
await runFlow(bot, trigger, 'Staging', stageStoreLocation);
break;
case 'migrateStore':
await runFlow(bot, trigger, 'Migrating store', migrateStoreLocation);
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;
}
});
}