feat: append_options en dynamic_list con redirect a otro flow

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 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-28 20:29:51 -05:00
co-authored by Claude Sonnet 4.6
parent 91dd84cc8d
commit 0df08bf953
+42 -5
View File
@@ -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)],