From a7413075c3144117adb1b2865c51372b5e36929f Mon Sep 17 00:00:00 2001 From: Azreen Jamal Date: Tue, 3 Mar 2026 04:19:37 +0800 Subject: [PATCH] telegram bot: fix env loading, remove markdown, clear stale updates --- telegram-bot/bot.err | 24 ------------------------ telegram-bot/bot.log | 4 +++- telegram-bot/index.ts | 10 +++++++--- telegram-bot/install.sh | 2 +- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/telegram-bot/bot.err b/telegram-bot/bot.err index 8587574..e69de29 100644 --- a/telegram-bot/bot.err +++ b/telegram-bot/bot.err @@ -1,24 +0,0 @@ - 9 | const SSH_USER = process.env.SSH_USER || "root"; -10 | const SSH_HOST = process.env.SSH_HOST!; -11 | const SSH_PORT = process.env.SSH_PORT || "22"; -12 | const ALLOWED_USERS = process.env.TELEGRAM_ALLOWED_USERS?.split(",").map(Number) || []; -13 | -14 | if (!BOT_TOKEN) throw new Error("TELEGRAM_BOT_TOKEN missing from .env"); - ^ -error: TELEGRAM_BOT_TOKEN missing from .env - at /Users/azreenjamal/pi-vs-claude-code/telegram-bot/index.ts:14:27 - at loadAndEvaluateModule (2:1) - -Bun v1.3.10 (macOS arm64) - 9 | const SSH_USER = process.env.SSH_USER || "root"; -10 | const SSH_HOST = process.env.SSH_HOST!; -11 | const SSH_PORT = process.env.SSH_PORT || "22"; -12 | const ALLOWED_USERS = process.env.TELEGRAM_ALLOWED_USERS?.split(",").map(Number) || []; -13 | -14 | if (!BOT_TOKEN) throw new Error("TELEGRAM_BOT_TOKEN missing from .env"); - ^ -error: TELEGRAM_BOT_TOKEN missing from .env - at /Users/azreenjamal/pi-vs-claude-code/telegram-bot/index.ts:14:27 - at loadAndEvaluateModule (2:1) - -Bun v1.3.10 (macOS arm64) diff --git a/telegram-bot/bot.log b/telegram-bot/bot.log index a5c1bb5..43d485a 100644 --- a/telegram-bot/bot.log +++ b/telegram-bot/bot.log @@ -1,3 +1,5 @@ 🚀 Bot starting... ✅ @cr_management_smart_bot is live -🔧 [775071081] run_command: free -h +📤 [775071081] reply length: 504 +🔧 [775071081] run_command: top -bn1 | head -20 +📤 [775071081] reply length: 585 diff --git a/telegram-bot/index.ts b/telegram-bot/index.ts index 074fc5c..c524713 100644 --- a/telegram-bot/index.ts +++ b/telegram-bot/index.ts @@ -253,12 +253,16 @@ bot.on("message:text", async (ctx) => { try { const reply = await chat(userId, msg); + console.log(`📤 [${userId}] reply length: ${reply.length}`); // Split long messages (Telegram 4096 char limit) const chunks = reply.match(/[\s\S]{1,4000}/g) || ["(empty)"]; for (const chunk of chunks) { - await ctx.reply(chunk, { parse_mode: "Markdown" }).catch(() => - ctx.reply(chunk) // retry without markdown if it fails - ); + try { + await ctx.reply(chunk); + } catch (sendErr: any) { + console.error(`❌ [${userId}] send failed:`, sendErr.message); + await ctx.reply("⚠️ Failed to format response. Check logs."); + } } } catch (err: any) { console.error(`❌ [${userId}]`, err); diff --git a/telegram-bot/install.sh b/telegram-bot/install.sh index ce6a611..cb854cc 100755 --- a/telegram-bot/install.sh +++ b/telegram-bot/install.sh @@ -32,7 +32,7 @@ cat > "$PLIST_PATH" < /bin/bash -c - source ${PROJECT_DIR}/.env && exec ${BUN_PATH} run ${BOT_DIR}/index.ts + set -a; source ${PROJECT_DIR}/.env; set +a; exec ${BUN_PATH} run ${BOT_DIR}/index.ts WorkingDirectory ${BOT_DIR}