45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
// Intent observe_crm_pipeline — manual trigger + read report
|
|
// Doctrine 62 Phase 2 (observation)
|
|
|
|
if (!function_exists('wevia_crm_observe_run')) {
|
|
function wevia_crm_observe_run($msg) {
|
|
if (!$msg) return false;
|
|
|
|
// Match: "observe crm", "check crm pipeline", "vérifier crm", "regarde crm"
|
|
if (!preg_match('/\b(observe|check|verif|regarde|scan)\s+(crm|pipeline|deliverads)\b/i', $msg)) return false;
|
|
|
|
$out = ['intent' => 'observe_crm_pipeline', 'tool' => 'crm_observer'];
|
|
|
|
// 1. Trigger the Python script
|
|
$cmd = "sudo -n -u www-data timeout 60 python3 /opt/weval-l99/crm-observation.py 2>&1 | tail -c 1500";
|
|
$exec_out = shell_exec($cmd);
|
|
$out['script_output'] = trim($exec_out);
|
|
|
|
// 2. Read latest report
|
|
$report_file = '/var/www/html/api/crm-observation-latest.json';
|
|
if (is_readable($report_file)) {
|
|
$out['report'] = json_decode(file_get_contents($report_file), true);
|
|
}
|
|
|
|
// 3. Link to dashboard
|
|
$out['dashboard_url'] = 'https://weval-consulting.com/crm-pipeline-live.html';
|
|
$out['api_url'] = 'https://weval-consulting.com/api/crm-pipeline-live.php?action=status';
|
|
|
|
header("Content-Type: application/json");
|
|
echo json_encode($out, JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
// Auto-dispatch
|
|
$_obs_msg = '';
|
|
$_body = @file_get_contents('php://input');
|
|
if ($_body) {
|
|
$_j = @json_decode($_body, true);
|
|
if (is_array($_j) && !empty($_j['message'])) $_obs_msg = $_j['message'];
|
|
}
|
|
if (!$_obs_msg) $_obs_msg = $_POST['message'] ?? $_GET['message'] ?? '';
|
|
|
|
if ($_obs_msg) wevia_crm_observe_run($_obs_msg);
|
|
}
|