Validate dynamic_list input and fix cosecha button IDs
- dynamic_list now stores valid IDs in collecting state; rejects free-text input that doesn't match a list option - Fixed submenu_ciclo_cosecha button IDs to match real flow names (ciclo_cosecha_dia / ciclo_cosecha_historico) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0ce766a9eb
commit
97a48d0fe4
+13
-3
@@ -136,6 +136,14 @@ class NormalBot
|
|||||||
$group = $col['meta_group'] ?? '';
|
$group = $col['meta_group'] ?? '';
|
||||||
$key = $col['meta_key'] ?? '';
|
$key = $col['meta_key'] ?? '';
|
||||||
$nextNode = $col['next_node'] ?? null;
|
$nextNode = $col['next_node'] ?? null;
|
||||||
|
$validIds = $col['__valid_ids'] ?? null;
|
||||||
|
|
||||||
|
if ($validIds !== null && !in_array(trim($input), $validIds, true)) {
|
||||||
|
return self::sendText(
|
||||||
|
'⚠️ Por favor selecciona una opción válida de la lista.',
|
||||||
|
$context['from'], $company
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$formData = $meta[$group] ?? [];
|
$formData = $meta[$group] ?? [];
|
||||||
$formData[$key] = trim($input);
|
$formData[$key] = trim($input);
|
||||||
@@ -182,10 +190,12 @@ class NormalBot
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$valueField = $flow['value_field'] ?? 'id';
|
||||||
$meta['collecting'] = [
|
$meta['collecting'] = [
|
||||||
'meta_group' => $flow['meta_group'] ?? '',
|
'meta_group' => $flow['meta_group'] ?? '',
|
||||||
'meta_key' => $flow['meta_key'] ?? '',
|
'meta_key' => $flow['meta_key'] ?? '',
|
||||||
'next_node' => $flow['next_node'] ?? null,
|
'next_node' => $flow['next_node'] ?? null,
|
||||||
|
'__valid_ids' => array_column($items, $valueField),
|
||||||
];
|
];
|
||||||
ConversationContext::updateMetadata($ctxId, $meta);
|
ConversationContext::updateMetadata($ctxId, $meta);
|
||||||
ConversationContext::updateNode($ctxId, 'collecting');
|
ConversationContext::updateNode($ctxId, 'collecting');
|
||||||
|
|||||||
Reference in New Issue
Block a user