Spaces:
Running
Running
VinOS Agent commited on
Commit Β·
dd615b1
1
Parent(s): 2c30532
feat(bot): add /research command for URL-based remixing
Browse files
server.js
CHANGED
|
@@ -625,6 +625,83 @@ Tell the AI what emotion or 'edge' you want.
|
|
| 625 |
return;
|
| 626 |
}
|
| 627 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
if (userText === '/turbo') {
|
| 629 |
const db = memory.readDB();
|
| 630 |
if (!db.user_profile_snapshot) db.user_profile_snapshot = {};
|
|
|
|
| 625 |
return;
|
| 626 |
}
|
| 627 |
|
| 628 |
+
if (userText && userText.toLowerCase().startsWith('/research')) {
|
| 629 |
+
const url = userText.replace(/^\/research\s*/i, '').trim();
|
| 630 |
+
if (!url) {
|
| 631 |
+
await apiCaller.sendTelegramMessage(chatId, "β Usage: /research [url]");
|
| 632 |
+
return;
|
| 633 |
+
}
|
| 634 |
+
await apiCaller.sendTelegramMessage(chatId, `π <b>Research Auto-Pilot</b>\nAnalyzing URL...`);
|
| 635 |
+
|
| 636 |
+
const researchModule = require('./research');
|
| 637 |
+
const aiContent = require('./ai-content');
|
| 638 |
+
const imageGen = require('./image-gen');
|
| 639 |
+
const scheduler = require('./scheduler');
|
| 640 |
+
|
| 641 |
+
const scrapeRes = await researchModule.scrapePost(url);
|
| 642 |
+
if (!scrapeRes.success) {
|
| 643 |
+
await apiCaller.sendTelegramMessage(chatId, `β Scrape failed: ${scrapeRes.error}`);
|
| 644 |
+
return;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
await apiCaller.sendTelegramMessage(chatId, `π§ Scrape successful! Remixing content...`);
|
| 648 |
+
const remixRes = await aiContent.remix(scrapeRes.data);
|
| 649 |
+
if (!remixRes.success) {
|
| 650 |
+
await apiCaller.sendTelegramMessage(chatId, `β AI Remix failed: ${remixRes.error}`);
|
| 651 |
+
return;
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
const v1 = remixRes.data.variant_1;
|
| 655 |
+
await apiCaller.sendTelegramMessage(chatId, `π¨ Generating high-conversion visual...`);
|
| 656 |
+
const imgRes = await imageGen.generateAndUpload(v1.visual_prompt, 'res_v1');
|
| 657 |
+
|
| 658 |
+
if (imgRes.success) v1.mediaUrl = imgRes.publicUrl;
|
| 659 |
+
|
| 660 |
+
// Save draft
|
| 661 |
+
const draftId = `res_${Date.now().toString().slice(-6)}`;
|
| 662 |
+
const draftPost = {
|
| 663 |
+
id: draftId,
|
| 664 |
+
status: 'draft',
|
| 665 |
+
created: new Date().toISOString(),
|
| 666 |
+
input: url,
|
| 667 |
+
platform: scrapeRes.data.platform || 'web',
|
| 668 |
+
sourceData: scrapeRes.data,
|
| 669 |
+
type: 'standard',
|
| 670 |
+
v1,
|
| 671 |
+
v2: remixRes.data.variant_2,
|
| 672 |
+
v3: remixRes.data.variant_3
|
| 673 |
+
};
|
| 674 |
+
|
| 675 |
+
scheduler.config.posts.push(draftPost);
|
| 676 |
+
scheduler.saveDB();
|
| 677 |
+
|
| 678 |
+
if (imgRes.success && v1.mediaUrl) {
|
| 679 |
+
try {
|
| 680 |
+
const FormData = require('form-data');
|
| 681 |
+
const fForm = new FormData();
|
| 682 |
+
fForm.append('chat_id', chatId);
|
| 683 |
+
|
| 684 |
+
if (v1.mediaUrl.startsWith('/')) {
|
| 685 |
+
const fs = require('fs');
|
| 686 |
+
const path = require('path');
|
| 687 |
+
fForm.append('photo', fs.createReadStream(path.join(__dirname, 'public', v1.mediaUrl)));
|
| 688 |
+
} else {
|
| 689 |
+
fForm.append('photo', v1.mediaUrl);
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
fForm.append('caption', `β
<b>Research Draft Ready!</b>\n\n${v1.ig_en.substring(0, 800)}...\n\nReview in Dashboard.`);
|
| 693 |
+
fForm.append('parse_mode', 'HTML');
|
| 694 |
+
await apiCaller.axiosIPv4.post(`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendPhoto`, fForm, { headers: fForm.getHeaders() });
|
| 695 |
+
} catch(e) {
|
| 696 |
+
await apiCaller.sendTelegramMessage(chatId, `β
<b>Research Draft Ready!</b>\n(Image generated but failed to send preview via Telegram)\n\nReview in Dashboard.`);
|
| 697 |
+
}
|
| 698 |
+
} else {
|
| 699 |
+
await apiCaller.sendTelegramMessage(chatId, `β
<b>Research Draft Ready! (No Image)</b>\n\n${v1.ig_en.substring(0, 800)}...\n\nReview in Dashboard.`);
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
return;
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
if (userText === '/turbo') {
|
| 706 |
const db = memory.readDB();
|
| 707 |
if (!db.user_profile_snapshot) db.user_profile_snapshot = {};
|