import {
fetchComponentByName,
fetchSummary,
fetchIncidents,
formatComponentLine,
formatOverallStatus,
formatIncidentLine,
statusIndicator,
humanizeStatus,
STATUS_URL,
} from "./status-fetcher.js";
/**
* Register info commands: /help, /status, /history, /uptime
*/
export function registerInfoCommands(bot) {
bot.command("help", async (ctx) => {
await ctx.reply(
`Claude Status Bot — Help\n\n` +
`/start\n` +
`Subscribe to Claude status notifications.\n` +
`Default: incidents + component updates.\n\n` +
`/stop\n` +
`Unsubscribe from all notifications.\n\n` +
`/status [component]\n` +
`Show current status of all components.\n` +
`Add a component name for a specific check.\n` +
`Example: /status api\n\n` +
`/subscribe <type>\n` +
`Set what notifications you receive.\n` +
`Options: incident, component, all\n` +
`Example: /subscribe incident\n\n` +
`/history [count]\n` +
`Show recent incidents. Default: 5, max: 10.\n` +
`Example: /history 3\n\n` +
`/uptime\n` +
`Show current component health overview.\n\n` +
`status.claude.com`,
{ parse_mode: "HTML", disable_web_page_preview: true }
);
});
bot.command("status", async (ctx) => {
const args = ctx.match?.trim();
try {
if (args) {
const component = await fetchComponentByName(args);
if (!component) {
await ctx.reply(`Component "${args}" not found.`, { parse_mode: "HTML" });
return;
}
await ctx.reply(formatComponentLine(component), { parse_mode: "HTML" });
} else {
const summary = await fetchSummary();
const components = summary.components.filter((c) => !c.group);
const overall = formatOverallStatus(summary.status.indicator);
const lines = components.map(formatComponentLine);
const updated = new Date(summary.page.updated_at).toLocaleString("en-US", {
dateStyle: "medium", timeStyle: "short", timeZone: "UTC",
});
await ctx.reply(
`${overall}\n\n` +
`${lines.join("\n")}\n\n` +
`Updated: ${updated} UTC\n` +
`View full status page`,
{ parse_mode: "HTML", disable_web_page_preview: true }
);
}
} catch {
await ctx.reply("Unable to fetch status. Please try again later.");
}
});
bot.command("history", async (ctx) => {
const arg = ctx.match?.trim();
const count = Math.min(Math.max(parseInt(arg, 10) || 5, 1), 10);
try {
const incidents = await fetchIncidents(count);
if (incidents.length === 0) {
await ctx.reply("No recent incidents found.", { parse_mode: "HTML" });
return;
}
const lines = incidents.map(formatIncidentLine);
await ctx.reply(
`Recent Incidents\n\n` +
`${lines.join("\n\n")}\n\n` +
`View full history`,
{ parse_mode: "HTML", disable_web_page_preview: true }
);
} catch {
await ctx.reply("Unable to fetch incident history. Please try again later.");
}
});
bot.command("uptime", async (ctx) => {
try {
const summary = await fetchSummary();
const components = summary.components.filter((c) => !c.group);
const overall = formatOverallStatus(summary.status.indicator);
const lines = components.map((c) => {
const indicator = statusIndicator(c.status);
const upSince = new Date(c.updated_at).toLocaleString("en-US", {
dateStyle: "medium", timeStyle: "short", timeZone: "UTC",
});
return `${indicator} ${c.name}\n Status: ${humanizeStatus(c.status)}\n Last change: ${upSince} UTC`;
});
await ctx.reply(
`${overall}\n\n` +
`${lines.join("\n\n")}\n\n` +
`Uptime % not available via public API.\n` +
`View uptime on status page`,
{ parse_mode: "HTML", disable_web_page_preview: true }
);
} catch {
await ctx.reply("Unable to fetch uptime data. Please try again later.");
}
});
}