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)],