From 9509c3b4fc6784e459ca9c0409e16ac6cb4b5a4e Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sun, 5 Jul 2026 20:07:44 -0500 Subject: [PATCH] feat: add skip_if support to collect_and_post flow fields MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- services/NormalBot.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/services/NormalBot.php b/services/NormalBot.php index 90cf2a8..45c9f98 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -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)) {