collabSupport/commands/woSummary.js
Joseph McQueen 1117be40cc Format chat footers in DISPLAY_TIMEZONE instead of UTC.
Docker hosts default to UTC, so bare toLocaleTimeString() showed
wrong "Last checked" times in avstatus and other commands. Add
formatDisplayTime() (default America/New_York, overridable via
DISPLAY_TIMEZONE) and use it across renderers and command footers.
2026-07-21 14:41:26 -04:00

43 lines
No EOL
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// src/commands/woSummary.js
import { collectWoSummary } from '../services/woService.js';
import { logger } from '../utils/logger.js';
import { formatDisplayTime } from '../utils/time.js';
export async function handleWoSummary(bot, trigger) {
logger('wo:summary', 'Handler entered');
// Support both Webex (args) and HTTP (query)
const query = trigger.query || {};
const args = trigger.args || [];
// Get work order number from args or query param
const woNumber = (args[0] || query.woNumber || query.wo || query.workorder || query.id || '')
.trim();
if (!woNumber || !/^\d+$/.test(woNumber)) {
const usage = '**Work Order Summary Usage:**\n' +
'`/woSummary 123456` → Get detailed summary for a specific work order\n\n' +
'Also works via HTTP: `?woNumber=123456`';
await bot.say('markdown', usage);
return;
}
logger('wo:summary', `Fetching summary for work order ${woNumber}`);
try {
const summary = await collectWoSummary(woNumber);
let reply = `**Work Order Summary ${woNumber}**\n\n`;
reply += `${summary || 'No summary data available.'}\n`;
reply += `\n*Last checked: ${formatDisplayTime()}*`;
await bot.say('markdown', reply.trim());
logger('wo:summary', `Successfully returned summary for WO ${woNumber}`);
} catch (err) {
logger('wo:summary', `Error fetching summary for WO ${woNumber}: ${err.message}`, 'error');
await bot.say('markdown', `❌ Error fetching work order summary for **${woNumber}**: ${err.message}`);
}
}