Multi-integration Webex chat/HTTP bot that unifies phone, AV, and network status for retail store support. Consolidates data from Webex Calling, Meraki, Workspace ONE (MDM), Atlas AMP, RED digital signage, and OptiSigns into rich per-store status commands. Key surfaces: - /phonestatus, /avstatus — per-store phone & AV device reports with clickable Meraki deep-links and per-port detail. - /webexhost — check/assign Webex Meetings host licenses via the Service App; adaptive-card confirmation flow, HTTP-API-gated. - /offboarduser — full Webex Admin offboarding (auth revoke, device wipe, license removal); adaptive-card confirmation. - /jirapoll — on-demand trigger for the hourly Jira poller. - /bulkavstatuscsv — bulk store CSV export with concurrency limits. Automation: - Hourly Jira poller (node-cron) with an X.AI (Grok) ticket classifier that categorizes unassigned tickets as phone/av/skip, extracts store numbers from free-text, and enriches Jira with the same detailed markdown the chat commands emit (converted to Jira ADF, preserves bold + Meraki links). Idempotent via a `bot-enriched` Jira label. Architecture: - Node.js 20+, ESM, Express 5, webex-node-bot-framework. - Layered integrations (integrations/*), services (services/*), commands (commands/*), utils (utils/*). - Shared markdown renderers (services/renderers/*) feed both chat handlers and the Jira poller so the two surfaces stay in sync. - Hand-rolled markdown-to-ADF converter (utils/markdownToAdf.js) — no new npm dependency. - Node built-in test runner (`node --test tests/*.test.js`), 30 tests covering the converter, renderers, and poller ADF assembly. Docker + docker-compose deployment. Config via .env (see .env.example for the full option surface).
103 lines
No EOL
3.7 KiB
JavaScript
103 lines
No EOL
3.7 KiB
JavaScript
// src/services/jiraService.js
|
|
import jira from '../integrations/jira/JiraClient.js';
|
|
import { logger } from '../utils/logger.js';
|
|
|
|
const componentMap = {
|
|
av: 'Audio Visual',
|
|
audio: 'Audio Visual',
|
|
visual: 'Audio Visual',
|
|
voice: 'Communication Services',
|
|
phone: 'Communication Services',
|
|
phones: 'Communication Services',
|
|
telephony: 'Communication Services',
|
|
comm: 'Communication Services',
|
|
mobility: 'Mobility',
|
|
mobile: 'Mobility',
|
|
wireless: 'Mobility',
|
|
};
|
|
|
|
const projects = ['SUPPORT', 'SS'];
|
|
|
|
// ==================== STORE + COMPONENT ====================
|
|
export async function getJiraTicketsForComponentWithStore(storeNumber, componentInput) {
|
|
if (!storeNumber || !componentInput) return [];
|
|
|
|
const normalized = componentInput.toLowerCase().trim();
|
|
const componentName = componentMap[normalized] || componentInput;
|
|
const paddedStore = storeNumber.toString().padStart(5, '0');
|
|
|
|
const projectClause = projects.map(p => `project = ${p}`).join(' OR ');
|
|
|
|
const jql = `(${projectClause})
|
|
AND "Store Number" = "${paddedStore}"
|
|
AND component = "${componentName}"
|
|
ORDER BY updated DESC`;
|
|
|
|
try {
|
|
const result = await jira.search(jql, 'key,summary,status,resolution,assignee,created,resolved,components', 20);
|
|
return result.issues || [];
|
|
} catch (err) {
|
|
logger('jira:service', `Failed store+component search`, 'warn');
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// ==================== STORE ONLY ====================
|
|
export async function getJiraTicketsForStore(storeNumber) {
|
|
if (!storeNumber) return [];
|
|
|
|
const paddedStore = storeNumber.toString().padStart(5, '0');
|
|
const projectClause = projects.map(p => `project = ${p}`).join(' OR ');
|
|
|
|
const jql = `(${projectClause}) AND "Store Number" = "${paddedStore}" ORDER BY updated DESC`;
|
|
|
|
logger('jira:service', `Searching store ${paddedStore} with JQL: ${jql}`, 'debug');
|
|
|
|
try {
|
|
const result = await jira.search(jql, 'key,summary,status,resolution,assignee,created,resolved,components', 30);
|
|
logger('jira:service', `Found ${result.issues?.length || 0} tickets for store ${paddedStore}`, 'debug');
|
|
return result.issues || [];
|
|
} catch (err) {
|
|
logger('jira:service', `Failed store search for ${paddedStore}: ${err.message}`, 'error');
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// ==================== COMPONENT ONLY ====================
|
|
export async function getJiraTicketsForComponent(componentInput) {
|
|
if (!componentInput) return [];
|
|
|
|
const normalized = componentInput.toLowerCase().trim();
|
|
const componentName = componentMap[normalized] || componentInput;
|
|
|
|
const projectClause = projects.map(p => `project = ${p}`).join(' OR ');
|
|
|
|
const jql = `(${projectClause}) AND component = "${componentName}" ORDER BY updated DESC`;
|
|
|
|
try {
|
|
const result = await jira.search(jql, 'key,summary,status,resolution,assignee,created,resolved,components', 15);
|
|
return result.issues || [];
|
|
} catch (err) {
|
|
logger('jira:service', `Failed component search`, 'error');
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// ==================== SHARED HELPERS (for commands consistency) ====================
|
|
|
|
export function getStatusEmoji(status) {
|
|
const s = (status || '').toLowerCase();
|
|
if (s.includes('resolved') || s.includes('done') || s.includes('fixed')) return '✅';
|
|
if (s.includes('in progress') || s.includes('open')) return '🔄';
|
|
if (s.includes('pending')) return '⏳';
|
|
return '📌';
|
|
}
|
|
|
|
export function calculateDaysOpen(created, resolvedOrUpdated) {
|
|
if (!created) return '—';
|
|
const start = new Date(created);
|
|
const end = resolvedOrUpdated ? new Date(resolvedOrUpdated) : new Date();
|
|
const diffTime = Math.abs(end - start);
|
|
const days = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
return isNaN(days) ? '—' : days;
|
|
} |