0ba42bdff77e9cd0e3dca65ab26914f6aee16c9e

Author
TheEdgeOfRage <git@theedgeofrage.com>
Committer
TheEdgeOfRage <git@theedgeofrage.com>
Date

Message

Report config errors on tool call

Diff

 1diff --git a/src/main.ts b/src/main.ts
 2index 72704a2fd9fd06542ae10224ed2aa1aee6611791..fde5979698f5ea1ada071018dff2df166370caf0 100644
 3--- a/src/main.ts
 4+++ b/src/main.ts
 5@@ -35,16 +35,24 @@ function loadConfig(): Config {
 6 }
 7 
 8 export const OpenCodeTelegram: Plugin = async ({ client, directory }) => {
 9-  const { token, allowedUsers } = loadConfig();
10-
11   init(client, directory);
12 
13+  let config: Config | null = null;
14+  let configError: string | null = null;
15+  try {
16+    config = loadConfig();
17+  } catch (err) {
18+    configError = String(err instanceof Error ? err.message : err);
19+    log.error("config load failed:", configError);
20+  }
21+
22   let bot: Bot | null = null;
23   const autoConnect = process.env.TELEGRAM_AUTOCONNECT === "1";
24 
25   async function connect(): Promise<string> {
26+    if (!config) return `error: ${configError}`;
27     if (bot) return "already connected";
28-    bot = createBot(token!, allowedUsers);
29+    bot = createBot(config.token, config.allowedUsers);
30     await bot.api.setMyCommands(BOT_COMMANDS);
31     log.info("telegram bot starting long-polling...");
32     bot.start();