telegram bot: fix env loading, remove markdown, clear stale updates
This commit is contained in:
@@ -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)
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
🚀 Bot starting...
|
🚀 Bot starting...
|
||||||
✅ @cr_management_smart_bot is live
|
✅ @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
|
||||||
|
|||||||
@@ -253,12 +253,16 @@ bot.on("message:text", async (ctx) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const reply = await chat(userId, msg);
|
const reply = await chat(userId, msg);
|
||||||
|
console.log(`📤 [${userId}] reply length: ${reply.length}`);
|
||||||
// Split long messages (Telegram 4096 char limit)
|
// Split long messages (Telegram 4096 char limit)
|
||||||
const chunks = reply.match(/[\s\S]{1,4000}/g) || ["(empty)"];
|
const chunks = reply.match(/[\s\S]{1,4000}/g) || ["(empty)"];
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
await ctx.reply(chunk, { parse_mode: "Markdown" }).catch(() =>
|
try {
|
||||||
ctx.reply(chunk) // retry without markdown if it fails
|
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) {
|
} catch (err: any) {
|
||||||
console.error(`❌ [${userId}]`, err);
|
console.error(`❌ [${userId}]`, err);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ cat > "$PLIST_PATH" <<EOF
|
|||||||
<array>
|
<array>
|
||||||
<string>/bin/bash</string>
|
<string>/bin/bash</string>
|
||||||
<string>-c</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>
|
</array>
|
||||||
<key>WorkingDirectory</key>
|
<key>WorkingDirectory</key>
|
||||||
<string>${BOT_DIR}</string>
|
<string>${BOT_DIR}</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user