From 0df08bf9538c5539e1babf3bd6dd22db3627c33b Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 28 Jul 2026 20:29:51 -0500 Subject: [PATCH] feat: append_options en dynamic_list con redirect a otro flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Permite añadir opciones fijas al final de una lista dinámica. Si el usuario elige una de esas opciones, el bot redirige al flow con ese ID en vez de guardar el valor como campo del formulario. Usado para el botón "Ver más grupos" en el flujo de mantenimiento. Co-Authored-By: Claude Sonnet 4.6 --- services/NormalBot.php | 47 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/services/NormalBot.php b/services/NormalBot.php index 6a7cf7e..6decfc6 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -162,6 +162,18 @@ class NormalBot $resolved = $matched; } + // Si el valor resuelto es un redirect_id, navegar al flow sin guardar valor + $redirectIds = $col['__redirect_ids'] ?? []; + if (in_array($resolved, $redirectIds, true)) { + unset($meta['collecting']); + ConversationContext::updateMetadata($ctxId, $meta); + ConversationContext::updateNode($ctxId, $resolved); + if (isset($flows[$resolved])) { + return self::handleFlow($flows[$resolved], $context, $company, $ctxId, $menus); + } + return null; + } + $formData = $meta[$group] ?? []; $formData[$key] = $resolved; $meta[$group] = $formData; @@ -278,12 +290,23 @@ class NormalBot ConversationContext::updateMetadata($ctxId, $meta); } + // Opciones fijas que redirigen a otro flow en vez de guardar el valor + $redirectIds = []; + $appendOptions = $flow['append_options'] ?? []; + foreach ($appendOptions as $opt) { + $optId = (string)($opt['id'] ?? ''); + if ($optId === '') continue; + $labelMap[(string)($opt['title'] ?? $optId)] = $optId; + $redirectIds[] = $optId; + } + $meta['collecting'] = [ - 'meta_group' => $group, - 'meta_key' => $key, - 'next_node' => $nextNode, - '__valid_ids' => array_column($items, $valueField), - '__label_map' => $labelMap, + 'meta_group' => $group, + 'meta_key' => $key, + 'next_node' => $nextNode, + '__valid_ids' => array_merge(array_column($items, $valueField), $redirectIds), + '__label_map' => $labelMap, + '__redirect_ids'=> $redirectIds, ]; ConversationContext::updateMetadata($ctxId, $meta); ConversationContext::updateNode($ctxId, 'collecting'); @@ -376,6 +399,20 @@ class NormalBot if (empty($sections)) return null; + // Añadir opciones fijas al final de la última sección + $appendOptions = $flow['append_options'] ?? []; + if (!empty($appendOptions)) { + $last = count($sections) - 1; + foreach ($appendOptions as $opt) { + $optId = (string)($opt['id'] ?? ''); + if ($optId === '') continue; + $sections[$last]['rows'][] = [ + 'id' => $optId, + 'title' => mb_substr((string)($opt['title'] ?? $optId), 0, 24), + ]; + } + } + return self::enqueueInteractive($to, [ 'type' => 'list', 'header' => ['type' => 'text', 'text' => mb_substr($flow['header'] ?? 'Selecciona', 0, 60)],