@inetafrica/open-claudia 1.1.7 → 1.1.8
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/bot.js +23 -6
- 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(
|
|
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");
|
|
@@ -1116,11 +1118,26 @@ bot.on("document", async (msg) => {
|
|
|
1116
1118
|
if (!isAuthorized(msg)) return;
|
|
1117
1119
|
if (!requireSession(msg)) return;
|
|
1118
1120
|
try {
|
|
1119
|
-
const
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1121
|
+
const fileName = msg.document.file_name || `file-${Date.now()}`;
|
|
1122
|
+
const mime = msg.document.mime_type || "";
|
|
1123
|
+
// Save with original name to files dir
|
|
1124
|
+
const savePath = path.join(FILES_DIR, fileName);
|
|
1125
|
+
const file = await bot.getFile(msg.document.file_id);
|
|
1126
|
+
const fileUrl = `https://api.telegram.org/file/bot${TOKEN}/${file.file_path}`;
|
|
1127
|
+
await new Promise((resolve, reject) => {
|
|
1128
|
+
const out = fs.createWriteStream(savePath);
|
|
1129
|
+
https.get(fileUrl, (res) => { res.pipe(out); out.on("finish", () => { out.close(); resolve(); }); }).on("error", reject);
|
|
1130
|
+
});
|
|
1131
|
+
const caption = msg.caption || "";
|
|
1132
|
+
const isImage = mime.startsWith("image/");
|
|
1133
|
+
let prompt;
|
|
1134
|
+
if (isImage) {
|
|
1135
|
+
prompt = `Image file saved at ${savePath}\n\nView it, then: ${caption || "Describe this image. If code/UI/error — explain and fix."}`;
|
|
1136
|
+
} else {
|
|
1137
|
+
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."}`;
|
|
1138
|
+
}
|
|
1139
|
+
await send(`File saved: ${fileName}`, { replyTo: msg.message_id });
|
|
1140
|
+
await runClaude(prompt, currentSession.dir, msg.message_id);
|
|
1124
1141
|
} catch (err) { await send(`Failed: ${err.message}`); }
|
|
1125
1142
|
});
|
|
1126
1143
|
|