feat: add skip_if support to collect_and_post flow fields

Allows fields to declare a skip_if condition so the bot skips them
based on previously collected values — used for eps/diagnostico fields
that only apply when novedad is an incapacidad type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-05 20:07:44 -05:00
co-authored by Claude Sonnet 4.6
parent 497743ceb1
commit 9509c3b4fc
+14
View File
@@ -509,6 +509,7 @@ class NormalBot
$cap['collected_labels'][$field['key']] = $value;
unset($cap['__awaiting_other']);
$cap['index'] = $idx + 1;
while ($cap['index'] < count($fields) && self::capShouldSkip($fields[$cap['index']], $cap['collected'])) { $cap['index']++; }
$meta['__cap'] = $cap;
ConversationContext::updateMetadata($ctxId, $meta);
if ($cap['index'] < count($fields)) {
@@ -566,6 +567,7 @@ class NormalBot
}
$cap['index'] = $idx + 1;
while ($cap['index'] < count($fields) && self::capShouldSkip($fields[$cap['index']], $cap['collected'])) { $cap['index']++; }
$meta['__cap'] = $cap;
ConversationContext::updateMetadata($ctxId, $meta);
@@ -713,6 +715,17 @@ class NormalBot
return self::sendText($text, $to, $company);
}
// skip_if: {"field":"novedad_id","not_in":["35","41"]} → skip this field if collected[field] not in list
private static function capShouldSkip(array $field, array $collected): bool
{
$si = $field['skip_if'] ?? null;
if (!$si) return false;
$val = (string)($collected[$si['field'] ?? ''] ?? '');
if (isset($si['not_in'])) return !in_array($val, array_map('strval', $si['not_in']));
if (isset($si['equals'])) return $val !== (string)$si['equals'];
return false;
}
private static function capFieldLabel(array $fields, string $key): string
{
foreach ($fields as $f) {
@@ -1128,6 +1141,7 @@ class NormalBot
$cap['collected_labels'][$field['key']] = $pending['label'];
unset($cap['__lookup_pending']);
$cap['index'] = $idx + 1;
while ($cap['index'] < count($fields) && self::capShouldSkip($fields[$cap['index']], $cap['collected'])) { $cap['index']++; }
$meta['__cap'] = $cap;
ConversationContext::updateMetadata($ctxId, $meta);
if ($cap['index'] < count($fields)) {