servchan/src/commands/woAddNote.js
jmcqueen cba047cb4e Add invoice approval cards, /confirmed close-out fallback, and /addNote.
Replace /completed with /confirmed that tries SC CONFIRMED then falls back to SC notes and ServChan close-out records when status is locked. Post invoice approval cards on PDF attach, track close-outs for cleanup, and add WO-space /addNote.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-25 12:59:54 -04:00

37 lines
1.4 KiB
JavaScript

// src/commands/woAddNote.js
import botClient from '../integrations/webex/botClient.js';
import { addWorkOrderNote } from '../integrations/serviceChannel/client.js';
import db from '../db/mappings.js';
import { logger } from '../utils/logger.js';
import { resolveDisplayName, resolveWoRoomContext } from '../utils/woRoomContext.js';
export async function handleWoAddNote(bot, trigger) {
logger('wo:addNote', 'HANDLER ENTERED');
const roomId = trigger.message?.roomId;
const isGroup = trigger.message?.roomType === 'group';
const noteText = (trigger.args || []).join(' ').trim();
if (!noteText) {
await bot.say('Usage: `/addNote your note text here` (WO space only).');
return;
}
const ctx = await resolveWoRoomContext({ db, botClient, roomId, isGroup });
if (!ctx.ok) {
await bot.say(ctx.error);
return;
}
const displayName = await resolveDisplayName(botClient, trigger.personId);
const scNote = `${displayName}: ${noteText}`;
try {
await addWorkOrderNote(ctx.workOrderId, scNote);
logger('wo:addNote', `Posted note to SC WO ${ctx.workOrderId} by ${displayName}`);
await bot.say(`Note added to the work order in ServiceChannel.`);
} catch (err) {
logger('wo:addNote', `Failed to post SC note for WO ${ctx.workOrderId}: ${err.message}`, 'error');
await bot.say(`Could not add the note in ServiceChannel: ${err.message}`);
}
}