feat: convert all WhatsApp menus from list to button type

- NormalBot: fix type check 'buttons' -> 'button' in buildMenuResponse
- DashboardController: botConfig editor now shows buttons editor for button-type menus,
  list fields (header/footer/button trigger) hidden for button type; menuTypeChange/addBtnRow
  JS functions toggle the UI; addMenu() defaults to button type
- DashboardController: renderMenuNode and renderFlowNode now read buttons[] array for
  button-type menus instead of only sections[].rows
- DashboardController: editMenu modal shows buttons editor or sections editor based on type;
  editMenuTypeToggle/addEditBtnRow; saveMenu reads buttons for button type
- public/index.php: botConfigSave handler parses menu_btn_id/menu_btn_title for button menus;
  saves compact {type,body,buttons} structure; list menus still save {type,header,...,sections}
- DB: migrated all list menus to button type for both companies (show_main_menu,
  submenu_informes, submenu_ciclos, show_menu_cat1, show_menu_cat2)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-27 19:27:37 -05:00
co-authored by Claude Sonnet 4.6
parent e4841e2741
commit 639c3e7938
3 changed files with 286 additions and 145 deletions
+36 -19
View File
@@ -324,40 +324,57 @@ $routes = [
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'] ?? [];
$menuKeys = $_POST['menu_key'] ?? [];
$menuTypes = $_POST['menu_type'] ?? [];
$menuBodies = $_POST['menu_body'] ?? [];
$menuHeaders = $_POST['menu_header'] ?? [];
$menuFooters = $_POST['menu_footer'] ?? [];
$menuBtnTrigger = $_POST['menu_button'] ?? [];
$menuSections = $_POST['menu_sections'] ?? [];
$menuBtnIds = $_POST['menu_btn_id'] ?? [];
$menuBtnTitles = $_POST['menu_btn_title'] ?? [];
$menus = [];
foreach ($menuKeys as $i => $mk) {
$mk = trim($mk);
$mk = trim($mk);
$type = $menuTypes[$i] ?? 'button';
if ($mk === '') continue;
$sections = [];
if (!empty($menuSections[$i])) {
foreach ($menuSections[$i] as $si => $section) {
if ($type === 'button') {
$buttons = [];
foreach ($menuBtnIds[$i] ?? [] as $j => $btnId) {
$btnId = trim($btnId);
$btnTitle = mb_substr(trim($menuBtnTitles[$i][$j] ?? ''), 0, 20);
if ($btnId !== '' && $btnTitle !== '') {
$buttons[] = ['id' => $btnId, 'title' => $btnTitle];
}
}
$menus[$mk] = [
'type' => 'button',
'body' => trim($menuBodies[$i] ?? ''),
'buttons' => $buttons,
];
} else {
$sections = [];
foreach ($menuSections[$i] ?? [] as $si => $section) {
$title = trim($section['title'] ?? '');
if ($title === '') continue;
$rows = [];
foreach ($section['rows'] ?? [] as $row) {
$rid = trim($row['id'] ?? '');
$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' => 'list',
'header' => trim($menuHeaders[$i] ?? ''),
'body' => trim($menuBodies[$i] ?? ''),
'footer' => trim($menuFooters[$i] ?? ''),
'button' => trim($menuBtnTrigger[$i] ?? ''),
'sections' => $sections,
];
}
$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;