peppa/apps/bot/src/index.ts
Асель 6e54fc69a6 PEP-91: Peppa reports its own errors to Bugsink — backend to PEP-api, browser to PEP-web
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 12:39:46 +05:00

30 lines
1.1 KiB
TypeScript

// Entry point: `peppa-bot` (launchd agent quest.telecom.peppa.bot).
import { createDb } from "@peppa/db";
import { loadEnv } from "@peppa/shared";
import { setRunnerClient } from "@peppa/runner";
import { installCrashReporting } from "@peppa/core";
import { createBot } from "./bot.ts";
import { TelegramApi } from "./telegram.ts";
const env = loadEnv();
if (!env.TELEGRAM_BOT_TOKEN) {
console.error("TELEGRAM_BOT_TOKEN is not set");
process.exit(1);
}
const db = createDb(env.PEPPA_DB);
// PEP-21: the bot only enqueues runner commands; the runner service (watchdog) runs them.
setRunnerClient(true, db);
// PEP-91: a crash of the bot goes to Bugsink before launchd restarts it.
installCrashReporting(db, "bot");
const bot = createBot({
db,
api: new TelegramApi(env.TELEGRAM_BOT_TOKEN, process.env.TELEGRAM_API_URL),
secret: env.TELEGRAM_BOT_TOKEN,
webUrl: env.PEPPA_WEB_URL,
log: (m) => console.log(`${new Date().toISOString()} ${m}`),
});
await bot.start();
for (const sig of ["SIGINT", "SIGTERM"] as const) {
process.on(sig, () => void bot.stop().then(() => process.exit(0)));
}