From b96dbcc394c532d994860bf3e5c27926e370815b Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 27 Jun 2026 18:46:35 -0500 Subject: [PATCH] feat: menus por permission_type (1=info, 2=informes, 3=completo) --- scripts/apply-menus.php | 56 +++++++++++++++++++++++++++++++++++++++++ services/NormalBot.php | 22 ++++++++++------ 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/scripts/apply-menus.php b/scripts/apply-menus.php index 45c1688..5ba3c89 100644 --- a/scripts/apply-menus.php +++ b/scripts/apply-menus.php @@ -96,6 +96,62 @@ $menuConfig = [ 'ciclo_cosecha_dia' => ['type' => 'function', 'function' => 'api_report', 'params' => ['endpoint_key' => 'cosecha_dn', 'filename' => 'ciclo_cosecha_hoy.xlsx', 'caption' => 'Ciclo de cosecha del día de hoy', 'date_mode' => 'today']], 'ciclo_cosecha_historico' => ['type' => 'function', 'function' => 'api_report', 'params' => ['endpoint_key' => 'cosecha_dn', 'filename' => 'ciclo_cosecha_30dias.xlsx', 'caption' => 'Histórico ciclos de cosecha últimos 30 días', 'date_mode' => 'last_30']], ], + 'per_type' => [ + '1' => [ + 'greeting' => '¡Bienvenido! Escribe *menu* para recibir información.', + 'fallback' => 'Escribe *menu* para recibir información.', + 'commands' => [ + 'menu' => 'show_menu_cat1', + 'info' => 'recibir_info_cat1', + ], + 'menus' => [ + 'show_menu_cat1' => [ + 'type' => 'list', + 'header' => 'Bienvenido', + 'body' => '¿Qué deseas hacer?', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Opciones', + 'rows' => [ + ['id' => 'recibir_info_cat1', 'title' => 'Recibir Información', 'description' => 'Información útil para ti'], + ], + ], + ], + ], + ], + 'flows' => [ + 'show_menu_cat1' => ['type' => 'menu', 'menu' => 'show_menu_cat1'], + 'recibir_info_cat1' => ['type' => 'function', 'function' => 'forward_to_ai'], + ], + ], + '2' => [ + 'greeting' => '¡Bienvenido! Escribe *menu* para descargar informes.', + 'fallback' => 'Escribe *menu* para descargar informes.', + 'commands' => [ + 'menu' => 'show_menu_cat2', + 'informes' => 'descargar_informes', + ], + 'menus' => [ + 'show_menu_cat2' => [ + 'type' => 'list', + 'header' => 'Menú', + 'body' => 'Selecciona una opción:', + 'footer' => 'Palmas360', + 'button' => 'Ver opciones', + 'sections' => [ + [ + 'title' => 'Opciones', + 'rows' => [ + ['id' => 'descargar_informes', 'title' => 'Descargar Informes', 'description' => 'Accede a tus informes'], + ], + ], + ], + ], + ], + ], + ], ]; $companies = CompanyRepository::findAll(true); diff --git a/services/NormalBot.php b/services/NormalBot.php index cfd62ac..6093132 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -6,9 +6,12 @@ class NormalBot public static function process(array $company, array $context, string $input): ?array { $config = self::getConfig($company); - $commands = $config['commands'] ?? []; - $flows = $config['flows'] ?? []; - $menus = $config['menus'] ?? []; + $permType = (string)($company['_permission_type'] ?? 1); + $perType = $config['per_type'][$permType] ?? []; + + $commands = $perType['commands'] ?? $config['commands'] ?? []; + $flows = array_merge($config['flows'] ?? [], $perType['flows'] ?? []); + $menus = array_merge($config['menus'] ?? [], $perType['menus'] ?? []); $ctxId = null; $botCtx = ConversationContext::getOrCreate((int)$company['id'], $context['from'], 'normal'); @@ -43,18 +46,19 @@ class NormalBot return null; } - $greeting = $config['greeting'] ?? null; + $greeting = $perType['greeting'] ?? $config['greeting'] ?? null; if ($greeting !== null && $currentNode === null) { ConversationContext::updateNode($ctxId, 'greeting'); - if (isset($flows['greeting'])) { - return self::handleFlow($flows['greeting'], $context, $company, $ctxId); + $greetingFlowId = $perType['greeting_flow'] ?? 'greeting'; + if (isset($flows[$greetingFlowId])) { + return self::handleFlow($flows[$greetingFlowId], $context, $company, $ctxId); } return self::sendText($greeting, $context['from'], $company); } - $fallback = $config['fallback'] ?? null; + $fallback = $perType['fallback'] ?? $config['fallback'] ?? null; if ($fallback !== null) { return self::sendText($fallback, $context['from'], $company); } @@ -324,7 +328,9 @@ class NormalBot public static function processInteractive(array $company, array $context, string $input): ?array { $config = self::getConfig($company); - $flows = $config['flows'] ?? []; + $permType = (string)($company['_permission_type'] ?? 1); + $perType = $config['per_type'][$permType] ?? []; + $flows = array_merge($config['flows'] ?? [], $perType['flows'] ?? []); $botCtx = ConversationContext::getOrCreate((int)$company['id'], $context['from'], 'normal'); $ctxId = (int)$botCtx['id'];