"need intent + pattern"])); $file = "/var/www/html/api/wevia-smart-router.php"; $content = file_get_contents($file); // Check if intent already exists if(strpos($content, $q) !== false) { die(json_encode(["status"=>"exists","intent"=>$q])); } // Add new intent before "return null" $newline = " if(preg_match('/$pattern/',\\$q)) return['response'=>'$response','engine'=>'$engine','intent'=>'$q'];\n"; $content = str_replace(" return null;", $newline." return null;", $content); // Backup + write file_put_contents($file.".bak", file_get_contents($file)); file_put_contents($file, $content); // Verify $lint = trim(shell_exec("php -l $file 2>&1")); if(strpos($lint, "No syntax errors") === false) { // Rollback copy($file.".bak", $file); die(json_encode(["error"=>"PHP syntax error, rolled back","lint"=>$lint])); } echo json_encode(["status"=>"wired","intent"=>$q,"pattern"=>$pattern,"engine"=>$engine]);