/** * Foundational helpers for NODE bots — the library's deliberately * Node-only corner (process signals, KEV env resolution). Worker bots * use the worker-safe subpaths instead: `bot/session` (namespaced * sessions) and `bot/notify` (admin DMs) hold the pieces that never * needed an OS. * * `gracefulStart(bot, opts?)` — wires SIGINT/SIGTERM to bot.stop(), * runs an optional shutdown hook, force-kills if it hangs. DMs the * admin on start/stop by default (`@ started.` / * `@ shutting down.`) when `KEV.TELEGRAM_ADMIN_ID` is set — * pass `notifyAdmin: false` to disable. * * Peer dep: `gramio`. * * @example * import { Bot } from 'gramio' * import { redisStorage } from '@gramio/storage-redis' * import { botSession } from '@adriangalilea/utils/bot/session' * import { gracefulStart } from '@adriangalilea/utils/bot/kit' * import { adminContext } from '@adriangalilea/utils/bot/admin' * import { kev } from '@adriangalilea/utils/platform/kev' * * const storage = redisStorage() // share across bots, safe * const userSession = botSession({ storage, initial: () => ({}) }) * * const bot = new Bot(process.env.BOT_TOKEN!) * .extend(adminContext(kev.int('TELEGRAM_ADMIN_ID', 123456789))) // env, id fallback * .extend(userSession) * .command('whoami', (ctx) => ctx.send(`admin? ${ctx.isAdmin}`)) * * await gracefulStart(bot, { onShutdown: () => db.end() }) */ import type { AnyBot } from "gramio"; export type GracefulStartOptions = { /** Runs after `bot.stop()` resolves, before `process.exit`. Close DBs, flush logs. */ onShutdown?: () => Promise | void; /** Process exit code on graceful shutdown. Default 0. */ exitCode?: number; /** Hard-kill after this many ms if shutdown hangs. Default 10000. */ forceExitAfterMs?: number; /** Logger. Default `console.log`. Set `false` to silence. */ log?: ((msg: string) => void) | false; /** * DM the admin on `bot.start()` and `bot.stop()` so you see lifecycle * events on your own Telegram. Body: `@ started.` and * `@ shutting down.` (the `username` comes from the * `info` passed to gramio's `onStart` / `onStop` hooks — no extra * `getMe` call). * * - `undefined` (default) — auto: read admin id from * `KEV.TELEGRAM_ADMIN_ID` (same source `adminContext` * uses). Silently skips if unset, so this is safe to * leave on for bots without the env var. * - `true` — same as default, but throws at start if KEV.TELEGRAM_ADMIN_ID * is missing. Use when you require the heartbeat. * - `number` — explicit Telegram user id to ping (bypasses KEV). * - `false` — disable entirely. * * Only graceful shutdowns notify — `process.exit(1)` from a crash or * the force-kill timer doesn't run `onStop`. Use this as an "I am * alive" heartbeat, not as crash detection. */ notifyAdmin?: boolean | number; }; export declare const gracefulStart: (bot: AnyBot, opts?: GracefulStartOptions) => Promise; //# sourceMappingURL=kit.d.ts.map