feat: add entry point with env validation and graceful shutdown
This commit is contained in:
+26
-1
@@ -1 +1,26 @@
|
|||||||
console.log("Claude Telegram Bot starting...");
|
import "dotenv/config";
|
||||||
|
import { createBot } from "./bot.js";
|
||||||
|
|
||||||
|
const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||||
|
const ownerId = process.env.TELEGRAM_OWNER_ID;
|
||||||
|
const apiKey = process.env.ANTHROPIC_API_KEY;
|
||||||
|
|
||||||
|
if (!token) throw new Error("TELEGRAM_BOT_TOKEN is required");
|
||||||
|
if (!ownerId) throw new Error("TELEGRAM_OWNER_ID is required");
|
||||||
|
if (!apiKey) throw new Error("ANTHROPIC_API_KEY is required");
|
||||||
|
|
||||||
|
const bot = createBot(token, Number(ownerId));
|
||||||
|
|
||||||
|
bot.start({
|
||||||
|
onStart: () => console.log("Bot started successfully"),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Graceful shutdown
|
||||||
|
const shutdown = () => {
|
||||||
|
console.log("Shutting down...");
|
||||||
|
bot.stop();
|
||||||
|
process.exit(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on("SIGINT", shutdown);
|
||||||
|
process.on("SIGTERM", shutdown);
|
||||||
|
|||||||
Reference in New Issue
Block a user