@gonzih/cc-tg 0.2.12 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bot.js +17 -5
- package/package.json +1 -1
package/dist/bot.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* One ClaudeProcess per chat_id — sessions are isolated per user.
|
|
4
4
|
*/
|
|
5
5
|
import TelegramBot from "node-telegram-bot-api";
|
|
6
|
-
import { existsSync, createWriteStream, mkdirSync } from "fs";
|
|
6
|
+
import { existsSync, createWriteStream, mkdirSync, statSync } from "fs";
|
|
7
7
|
import { resolve, basename, join } from "path";
|
|
8
8
|
import os from "os";
|
|
9
9
|
import { execSync } from "child_process";
|
|
@@ -23,7 +23,7 @@ const BOT_COMMANDS = [
|
|
|
23
23
|
{ command: "mcp_version", description: "Show cc-agent npm version and npx cache info" },
|
|
24
24
|
{ command: "clear_npx_cache", description: "Clear npx cache and restart MCP to pick up latest version" },
|
|
25
25
|
{ command: "restart", description: "Restart the bot process in-place" },
|
|
26
|
-
{ command: "get_file", description: "
|
|
26
|
+
{ command: "get_file", description: "Send a file from the server to this chat" },
|
|
27
27
|
];
|
|
28
28
|
const FLUSH_DELAY_MS = 800; // debounce streaming chunks into one Telegram message
|
|
29
29
|
const TYPING_INTERVAL_MS = 4000; // re-send typing action before Telegram's 5s expiry
|
|
@@ -440,6 +440,13 @@ export class CcTgBot {
|
|
|
440
440
|
console.log(`[claude:files] skipping sensitive file: ${filePath}`);
|
|
441
441
|
continue;
|
|
442
442
|
}
|
|
443
|
+
const fileSize = statSync(filePath).size;
|
|
444
|
+
const MAX_TG_FILE_BYTES = 50 * 1024 * 1024;
|
|
445
|
+
if (fileSize > MAX_TG_FILE_BYTES) {
|
|
446
|
+
const mb = (fileSize / (1024 * 1024)).toFixed(1);
|
|
447
|
+
this.bot.sendMessage(chatId, `File too large for Telegram (${mb}mb). Find it at: ${filePath}`).catch(() => { });
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
443
450
|
console.log(`[claude:files] uploading to telegram: ${filePath}`);
|
|
444
451
|
this.bot.sendDocument(chatId, filePath).catch((err) => console.error(`[tg:${chatId}] sendDocument failed for ${filePath}:`, err.message));
|
|
445
452
|
}
|
|
@@ -676,9 +683,7 @@ export class CcTgBot {
|
|
|
676
683
|
await this.bot.sendMessage(chatId, `File not found: ${filePath}`);
|
|
677
684
|
return;
|
|
678
685
|
}
|
|
679
|
-
|
|
680
|
-
const stat = statSync(filePath);
|
|
681
|
-
if (!stat.isFile()) {
|
|
686
|
+
if (!statSync(filePath).isFile()) {
|
|
682
687
|
await this.bot.sendMessage(chatId, `Not a file: ${filePath}`);
|
|
683
688
|
return;
|
|
684
689
|
}
|
|
@@ -686,6 +691,13 @@ export class CcTgBot {
|
|
|
686
691
|
await this.bot.sendMessage(chatId, "Access denied: sensitive file");
|
|
687
692
|
return;
|
|
688
693
|
}
|
|
694
|
+
const MAX_TG_FILE_BYTES = 50 * 1024 * 1024;
|
|
695
|
+
const fileSize = statSync(filePath).size;
|
|
696
|
+
if (fileSize > MAX_TG_FILE_BYTES) {
|
|
697
|
+
const mb = (fileSize / (1024 * 1024)).toFixed(1);
|
|
698
|
+
await this.bot.sendMessage(chatId, `File too large for Telegram (${mb}mb). Find it at: ${filePath}`);
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
689
701
|
await this.bot.sendDocument(chatId, filePath);
|
|
690
702
|
}
|
|
691
703
|
killSession(chatId, keepCrons = true) {
|