Files
ridebus-status/server/notify-cli.mjs
2026-10-13 02:24:39 +03:00

18 lines
1.1 KiB
JavaScript

import { loadConfig } from './config.mjs';
import { openStore } from './store.mjs';
import { sendTelegram } from './notifications.mjs';
const config = loadConfig();
const command = process.argv[2] || 'status';
if (command === 'status') {
const store = openStore(config.dbPath);
try { console.log(JSON.stringify({ enabled: config.telegram.enabled, queue: store.notificationStats() }, null, 2)); } finally { store.close(); }
} else if (command === 'test') {
if (!config.telegram.enabled) { console.error('Set TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID in .env first.'); process.exitCode = 1; }
else {
const result = await sendTelegram(config.telegram, config.telegram.locale === 'en' ? 'RideBus Status · Test notification. Monitoring alerts are connected.' : 'RideBus Status · Тестовое уведомление. Отправка сообщений подключена.');
console.log(result.ok ? 'Test notification delivered.' : `Delivery failed: ${result.reason}`);
if (!result.ok) process.exitCode = 1;
}
} else { console.error('Usage: npm run notify -- status | test'); process.exitCode = 1; }