cambios importantes
This commit is contained in:
@@ -282,6 +282,110 @@ $routes = [
|
||||
jsonResponse(200, ['status' => 'rejected', 'message' => 'Mensaje rechazado']);
|
||||
})()],
|
||||
|
||||
// ─── Admin: configurador visual del bot ────────────────────────────────
|
||||
['GET', '/admin/bot-config', fn() => DashboardController::botConfig()],
|
||||
|
||||
['POST', '/admin/bot-config/save', fn() => (function () {
|
||||
SessionAuth::require();
|
||||
$companyId = (int)($_POST['company_id'] ?? 0);
|
||||
if ($companyId === 0) { header('Location: /admin/bot-config?msg=error'); exit; }
|
||||
|
||||
$config = [];
|
||||
// Commands
|
||||
$keywords = $_POST['cmd_keyword'] ?? [];
|
||||
$actions = $_POST['cmd_action'] ?? [];
|
||||
$commands = [];
|
||||
foreach ($keywords as $i => $kw) {
|
||||
$kw = trim($kw);
|
||||
$act = trim($actions[$i] ?? '');
|
||||
if ($kw !== '' && $act !== '') $commands[$kw] = $act;
|
||||
}
|
||||
if (!empty($commands)) $config['commands'] = $commands;
|
||||
|
||||
// Menus
|
||||
$menuKeys = $_POST['menu_key'] ?? [];
|
||||
$menuTypes = $_POST['menu_type'] ?? [];
|
||||
$menuHeaders = $_POST['menu_header'] ?? [];
|
||||
$menuBodies = $_POST['menu_body'] ?? [];
|
||||
$menuFooters = $_POST['menu_footer'] ?? [];
|
||||
$menuButtons = $_POST['menu_button'] ?? [];
|
||||
$menuSections = $_POST['menu_sections'] ?? [];
|
||||
$menus = [];
|
||||
foreach ($menuKeys as $i => $mk) {
|
||||
$mk = trim($mk);
|
||||
if ($mk === '') continue;
|
||||
$sections = [];
|
||||
if (!empty($menuSections[$i])) {
|
||||
foreach ($menuSections[$i] as $si => $section) {
|
||||
$title = trim($section['title'] ?? '');
|
||||
if ($title === '') continue;
|
||||
$rows = [];
|
||||
foreach ($section['rows'] ?? [] as $row) {
|
||||
$rid = trim($row['id'] ?? '');
|
||||
$rtitle = trim($row['title'] ?? '');
|
||||
if ($rid === '' || $rtitle === '') continue;
|
||||
$rows[] = ['id' => $rid, 'title' => $rtitle, 'description' => trim($row['description'] ?? '')];
|
||||
}
|
||||
$sections[] = ['title' => $title, 'rows' => $rows];
|
||||
}
|
||||
}
|
||||
$menus[$mk] = [
|
||||
'type' => $menuTypes[$i] ?? 'list',
|
||||
'header' => trim($menuHeaders[$i] ?? ''),
|
||||
'body' => trim($menuBodies[$i] ?? ''),
|
||||
'footer' => trim($menuFooters[$i] ?? ''),
|
||||
'button' => trim($menuButtons[$i] ?? ''),
|
||||
'sections' => $sections,
|
||||
];
|
||||
}
|
||||
if (!empty($menus)) $config['menus'] = $menus;
|
||||
|
||||
// Flows
|
||||
$flowKeys = $_POST['flow_key'] ?? [];
|
||||
$flowTypes = $_POST['flow_type'] ?? [];
|
||||
$flowMessages = $_POST['flow_message'] ?? [];
|
||||
$flowFunctions = $_POST['flow_function'] ?? [];
|
||||
$flowMenus = $_POST['flow_menu'] ?? [];
|
||||
$flows = [];
|
||||
foreach ($flowKeys as $i => $fk) {
|
||||
$fk = trim($fk);
|
||||
if ($fk === '') continue;
|
||||
$ftype = $flowTypes[$i] ?? 'text';
|
||||
$f = ['type' => $ftype];
|
||||
if ($ftype === 'text') $f['message'] = trim($flowMessages[$i] ?? '');
|
||||
elseif ($ftype === 'function') $f['function'] = trim($flowFunctions[$i] ?? 'forward_to_ai');
|
||||
elseif ($ftype === 'menu') $f['menu'] = trim($flowMenus[$i] ?? '');
|
||||
$flows[$fk] = $f;
|
||||
}
|
||||
if (!empty($flows)) $config['flows'] = $flows;
|
||||
|
||||
// AI
|
||||
$aiPrompt = trim($_POST['ai_prompt'] ?? '');
|
||||
if ($aiPrompt !== '') $config['ai_prompt'] = $aiPrompt;
|
||||
$aiModel = trim($_POST['ai_model'] ?? '');
|
||||
if ($aiModel !== '') $config['ai_model'] = $aiModel;
|
||||
$aiTemp = trim($_POST['ai_temperature'] ?? '');
|
||||
if ($aiTemp !== '') $config['ai_temperature'] = (float)$aiTemp;
|
||||
$aiProvider = trim($_POST['ai_provider'] ?? '');
|
||||
if ($aiProvider !== '') $config['ai_provider'] = $aiProvider;
|
||||
|
||||
// General
|
||||
$greeting = trim($_POST['greeting'] ?? '');
|
||||
if ($greeting !== '') $config['greeting'] = $greeting;
|
||||
$fallback = trim($_POST['fallback'] ?? '');
|
||||
if ($fallback !== '') $config['fallback'] = $fallback;
|
||||
$ignorePrefixes = trim($_POST['ignore_prefixes'] ?? '');
|
||||
if ($ignorePrefixes !== '') {
|
||||
$config['ignore_prefixes'] = array_map('trim', explode("\n", $ignorePrefixes));
|
||||
}
|
||||
$approvalWebhook = trim($_POST['approval_webhook'] ?? '');
|
||||
if ($approvalWebhook !== '') $config['approval_webhook'] = $approvalWebhook;
|
||||
|
||||
CompanyRepository::save(['id' => $companyId, 'config_json' => json_encode($config, JSON_UNESCAPED_UNICODE)]);
|
||||
header('Location: /admin/bot-config?id=' . $companyId . '&msg=saved');
|
||||
exit;
|
||||
})()],
|
||||
|
||||
// ─── Admin: configuración general ──────────────────────────────────────
|
||||
['GET', '/admin/settings', fn() => DashboardController::settings()],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user