telegram bot: fix env loading, remove markdown, clear stale updates

This commit is contained in:
Azreen Jamal
2026-03-03 04:19:37 +08:00
parent dd2ce7e81f
commit a7413075c3
4 changed files with 11 additions and 29 deletions
-24
View File
@@ -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)
+3 -1
View File
@@ -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
+7 -3
View File
@@ -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);
+1 -1
View File
@@ -32,7 +32,7 @@ cat > "$PLIST_PATH" <<EOF
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>source ${PROJECT_DIR}/.env && exec ${BUN_PATH} run ${BOT_DIR}/index.ts</string>
<string>set -a; source ${PROJECT_DIR}/.env; set +a; exec ${BUN_PATH} run ${BOT_DIR}/index.ts</string>
</array>
<key>WorkingDirectory</key>
<string>${BOT_DIR}</string>