// 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))); }