@inetafrica/open-claudia 1.1.7 → 1.1.9

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.
Files changed (2) hide show
  1. package/bot.js +63 -13
  2. package/package.json +1 -1
package/bot.js CHANGED
@@ -178,8 +178,10 @@ bot.setMyCommands([
178
178
  ]);
179
179
 
180
180
  // Temp dir for media
181
- const TEMP_DIR = path.join(WORKSPACE, ".telegram-media");
181
+ const TEMP_DIR = path.join(CONFIG_DIR, "media");
182
+ const FILES_DIR = path.join(CONFIG_DIR, "files");
182
183
  if (!fs.existsSync(TEMP_DIR)) fs.mkdirSync(TEMP_DIR, { recursive: true });
184
+ if (!fs.existsSync(FILES_DIR)) fs.mkdirSync(FILES_DIR, { recursive: true });
183
185
 
184
186
  // ── Persistent state ───────────────────────────────────────────────
185
187
  const STATE_FILE = path.join(CONFIG_DIR, "state.json");
@@ -829,13 +831,14 @@ bot.onText(/\/upgrade$/, async (msg) => {
829
831
  if (!isOwner(msg)) return;
830
832
  await send("Upgrading...");
831
833
  try {
832
- const output = execSync("npm install -g @inetafrica/open-claudia@latest 2>&1", {
834
+ execSync("npm install -g @inetafrica/open-claudia@latest 2>&1", {
833
835
  encoding: "utf-8", timeout: 60000,
834
836
  env: { ...process.env, PATH: FULL_PATH },
835
837
  });
836
- const versionMatch = output.match(/@inetafrica\/open-claudia@([\d.]+)/);
837
- const version = versionMatch ? versionMatch[1] : "latest";
838
- await send(`Upgraded to v${version}. Restarting...`);
838
+ // Read version from newly installed package
839
+ const root = execSync("npm root -g", { encoding: "utf-8", env: { ...process.env, PATH: FULL_PATH } }).trim();
840
+ const newPkg = JSON.parse(fs.readFileSync(path.join(root, "@inetafrica", "open-claudia", "package.json"), "utf-8"));
841
+ await send(`Upgraded: v${CURRENT_VERSION} → v${newPkg.version}. Restarting...`);
839
842
  } catch (e) {
840
843
  await send(`Upgrade failed: ${e.message}`);
841
844
  return;
@@ -1116,11 +1119,26 @@ bot.on("document", async (msg) => {
1116
1119
  if (!isAuthorized(msg)) return;
1117
1120
  if (!requireSession(msg)) return;
1118
1121
  try {
1119
- const ext = path.extname(msg.document.file_name || ".txt");
1120
- const p = await downloadFile(msg.document.file_id, ext);
1121
- const caption = msg.caption || `Read ${msg.document.file_name} and summarize.`;
1122
- const prefix = (msg.document.mime_type || "").startsWith("image/") ? `Image at ${p}\n\nView it, then: ` : `File at ${p} (${msg.document.file_name})\n\n`;
1123
- await runClaude(prefix + caption, currentSession.dir, msg.message_id);
1122
+ const fileName = msg.document.file_name || `file-${Date.now()}`;
1123
+ const mime = msg.document.mime_type || "";
1124
+ // Save with original name to files dir
1125
+ const savePath = path.join(FILES_DIR, fileName);
1126
+ const file = await bot.getFile(msg.document.file_id);
1127
+ const fileUrl = `https://api.telegram.org/file/bot${TOKEN}/${file.file_path}`;
1128
+ await new Promise((resolve, reject) => {
1129
+ const out = fs.createWriteStream(savePath);
1130
+ https.get(fileUrl, (res) => { res.pipe(out); out.on("finish", () => { out.close(); resolve(); }); }).on("error", reject);
1131
+ });
1132
+ const caption = msg.caption || "";
1133
+ const isImage = mime.startsWith("image/");
1134
+ let prompt;
1135
+ if (isImage) {
1136
+ prompt = `Image file saved at ${savePath}\n\nView it, then: ${caption || "Describe this image. If code/UI/error — explain and fix."}`;
1137
+ } else {
1138
+ prompt = `File received: ${fileName} (${mime})\nSaved at: ${savePath}\n\nRead this file and ${caption || "summarize its contents. If it's code, explain what it does. If it's a document, give key points."}`;
1139
+ }
1140
+ await send(`File saved: ${fileName}`, { replyTo: msg.message_id });
1141
+ await runClaude(prompt, currentSession.dir, msg.message_id);
1124
1142
  } catch (err) { await send(`Failed: ${err.message}`); }
1125
1143
  });
1126
1144
 
@@ -1176,9 +1194,41 @@ bot.on("message", async (msg) => {
1176
1194
  if (!requireSession(msg)) return;
1177
1195
 
1178
1196
  let prompt = msg.text;
1179
- if (msg.reply_to_message && msg.reply_to_message.text) {
1180
- const ctx = msg.reply_to_message.text;
1181
- prompt = `Context:\n---\n${ctx.length > 500 ? ctx.slice(0, 500) + "..." : ctx}\n---\n\n${msg.text}`;
1197
+ const reply = msg.reply_to_message;
1198
+ if (reply) {
1199
+ let ctx = "";
1200
+ if (reply.text) {
1201
+ ctx = reply.text;
1202
+ }
1203
+ if (reply.caption) {
1204
+ ctx += (ctx ? "\n" : "") + reply.caption;
1205
+ }
1206
+ if (reply.document) {
1207
+ const fileName = reply.document.file_name || "unknown";
1208
+ const filePath = path.join(FILES_DIR, fileName);
1209
+ if (fs.existsSync(filePath)) {
1210
+ ctx += (ctx ? "\n" : "") + `[Attached file: ${fileName} at ${filePath}]`;
1211
+ } else {
1212
+ // Download the file from the replied message
1213
+ try {
1214
+ const file = await bot.getFile(reply.document.file_id);
1215
+ const fileUrl = `https://api.telegram.org/file/bot${TOKEN}/${file.file_path}`;
1216
+ await new Promise((resolve, reject) => {
1217
+ const out = fs.createWriteStream(filePath);
1218
+ https.get(fileUrl, (res) => { res.pipe(out); out.on("finish", () => { out.close(); resolve(); }); }).on("error", reject);
1219
+ });
1220
+ ctx += (ctx ? "\n" : "") + `[Attached file: ${fileName} at ${filePath}]`;
1221
+ } catch (e) {
1222
+ ctx += (ctx ? "\n" : "") + `[Attached file: ${fileName} — could not download]`;
1223
+ }
1224
+ }
1225
+ }
1226
+ if (reply.photo) {
1227
+ ctx += (ctx ? "\n" : "") + "[Attached photo]";
1228
+ }
1229
+ if (ctx) {
1230
+ prompt = `Replying to message:\n---\n${ctx.length > 1000 ? ctx.slice(0, 1000) + "..." : ctx}\n---\n\n${msg.text}`;
1231
+ }
1182
1232
  }
1183
1233
 
1184
1234
  await runClaude(prompt, currentSession.dir, msg.message_id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inetafrica/open-claudia",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Your always-on AI coding assistant — Claude Code via Telegram",
5
5
  "main": "bot.js",
6
6
  "bin": {