feat(market-intel): implement role-based campaign engine and gritty reporting
- Implementierung der rollenbasierten Campaign-Engine mit operativem Fokus (Grit). - Integration von Social Proof (Referenzkunden) in die E-Mail-Generierung. - Erweiterung des Deep Tech Audits um gezielte Wettbewerber-Recherche (Technographic Search). - Fix des Lösch-Bugs in der Target-Liste und Optimierung des Frontend-States. - Erweiterung des Markdown-Exports um transparente Proof-Links und Evidenz. - Aktualisierung der Dokumentation in readme.md und market_intel_backend_plan.md.
This commit is contained in:
@@ -269,6 +269,89 @@ app.post('/api/analyze-company', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// API-Endpunkt für generate-outreach
|
||||
app.post('/api/generate-outreach', async (req, res) => {
|
||||
console.log(`[${new Date().toISOString()}] HIT: /api/generate-outreach`);
|
||||
const { companyData, knowledgeBase, referenceUrl } = req.body;
|
||||
|
||||
if (!companyData || !knowledgeBase) {
|
||||
console.error('Validation Error: Missing companyData or knowledgeBase for generate-outreach.');
|
||||
return res.status(400).json({ error: 'Missing companyData or knowledgeBase' });
|
||||
}
|
||||
|
||||
const tempDataFilePath = path.join(__dirname, 'tmp', `outreach_data_${Date.now()}.json`);
|
||||
const tempContextFilePath = path.join(__dirname, 'tmp', `outreach_context_${Date.now()}.md`);
|
||||
const tmpDir = path.join(__dirname, 'tmp');
|
||||
if (!fs.existsSync(tmpDir)) {
|
||||
fs.mkdirSync(tmpDir);
|
||||
}
|
||||
|
||||
try {
|
||||
fs.writeFileSync(tempDataFilePath, JSON.stringify(companyData));
|
||||
fs.writeFileSync(tempContextFilePath, knowledgeBase);
|
||||
console.log(`Successfully wrote temporary files for outreach.`);
|
||||
|
||||
const pythonExecutable = path.join(__dirname, '..', '.venv', 'bin', 'python3');
|
||||
const pythonScript = path.join(__dirname, '..', 'market_intel_orchestrator.py');
|
||||
|
||||
const scriptArgs = [
|
||||
pythonScript,
|
||||
'--mode', 'generate_outreach',
|
||||
'--company_data_file', tempDataFilePath,
|
||||
'--context_file', tempContextFilePath,
|
||||
'--reference_url', referenceUrl || ''
|
||||
];
|
||||
|
||||
console.log(`Spawning Outreach Generation for ${companyData.companyName}...`);
|
||||
|
||||
const pythonProcess = spawn(pythonExecutable, scriptArgs, {
|
||||
env: { ...process.env, PYTHONPATH: path.join(__dirname, '..', '.venv', 'lib', 'python3.11', 'site-packages') }
|
||||
});
|
||||
|
||||
let pythonOutput = '';
|
||||
let pythonError = '';
|
||||
|
||||
pythonProcess.stdout.on('data', (data) => {
|
||||
pythonOutput += data.toString();
|
||||
});
|
||||
|
||||
pythonProcess.stderr.on('data', (data) => {
|
||||
pythonError += data.toString();
|
||||
});
|
||||
|
||||
pythonProcess.on('close', (code) => {
|
||||
console.log(`Outreach Generation finished with exit code: ${code}`);
|
||||
|
||||
// Clean up
|
||||
if (fs.existsSync(tempDataFilePath)) fs.unlinkSync(tempDataFilePath);
|
||||
if (fs.existsSync(tempContextFilePath)) fs.unlinkSync(tempContextFilePath);
|
||||
|
||||
if (code !== 0) {
|
||||
console.error(`Python script (generate_outreach) exited with error.`);
|
||||
return res.status(500).json({ error: 'Python script failed', details: pythonError });
|
||||
}
|
||||
try {
|
||||
const result = JSON.parse(pythonOutput);
|
||||
res.json(result);
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse Python output (generate_outreach) as JSON:', parseError);
|
||||
res.status(500).json({ error: 'Invalid JSON from Python script', rawOutput: pythonOutput, details: pythonError });
|
||||
}
|
||||
});
|
||||
|
||||
pythonProcess.on('error', (err) => {
|
||||
console.error(`FATAL: Failed to start python process for outreach.`, err);
|
||||
if (fs.existsSync(tempDataFilePath)) fs.unlinkSync(tempDataFilePath);
|
||||
if (fs.existsSync(tempContextFilePath)) fs.unlinkSync(tempContextFilePath);
|
||||
res.status(500).json({ error: 'Failed to start Python process', details: err.message });
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error(`Internal Server Error in /api/generate-outreach: ${err.message}`);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Start des Servers
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Node.js API Bridge running on http://localhost:${PORT}`);
|
||||
|
||||
Reference in New Issue
Block a user