feat: collect_and_post flow type — sequential field collection + POST

New flow type that asks the user for a configured list of fields one
by one, shows a summary with confirm/cancel, then POSTs all answers
as JSON to the configured endpoint with Bearer auth.

Config example:
  {
    "type": "collect_and_post",
    "endpoint_key": "subir_cosecha",
    "header": "🌿 Ciclos Cosecha",
    "confirm": true,
    "success_text": " Ciclo registrado.",
    "fields": [
      {"key":"fecha",    "label":"Fecha",    "prompt":"📅 ¿Fecha del ciclo? (YYYY-MM-DD)"},
      {"key":"cantidad", "label":"Racimos",  "prompt":"🔢 ¿Cantidad de racimos?"},
      {"key":"finca",    "label":"Finca",    "prompt":"🏡 ¿Nombre de la finca?"}
    ]
  }

POST payload: {fecha, cantidad, finca, telefono, nombre}

Also adds the UI panel in bot-config with dynamic add/remove field rows.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-29 11:06:42 -05:00
co-authored by Claude Sonnet 4.6
parent 32f87ef27c
commit 3c7ea9fdf9
3 changed files with 268 additions and 0 deletions
+32
View File
@@ -421,6 +421,13 @@ $routes = [
$flowFeHeaders = $_POST['flow_fe_header'] ?? [];
$flowFeQs = $_POST['flow_fe_question'] ?? [];
$flowFeSucTxts = $_POST['flow_fe_success'] ?? [];
$flowCapEps = $_POST['flow_cap_ep'] ?? [];
$flowCapHdrs = $_POST['flow_cap_header'] ?? [];
$flowCapSuccs = $_POST['flow_cap_success'] ?? [];
$flowCapCfmIdx = $_POST['flow_cap_confirm_idx'] ?? [];
$capFieldKeys = $_POST['cap_field_key'] ?? [];
$capFieldLbls = $_POST['cap_field_label'] ?? [];
$capFieldPrmts = $_POST['cap_field_prompt'] ?? [];
$flows = [];
foreach ($flowKeys as $i => $fk) {
@@ -481,6 +488,31 @@ $routes = [
$f['header'] = trim($flowFeHeaders[$i] ?? '');
$f['question'] = trim($flowFeQs[$i] ?? '');
$f['success_text'] = trim($flowFeSucTxts[$i] ?? '');
} elseif ($ftype === 'collect_and_post') {
$confirmIdx = $flowCapCfmIdx[$i] ?? (string)$i;
$confirmKey = 'flow_cap_confirm_' . $confirmIdx;
$fields = [];
// cap_field_* arrays are flat across ALL cap flows — we read only
// rows belonging to this card by matching the container's position.
// Since PHP flattens them, we track by finding all entries in sequence.
// Simple approach: take all submitted field rows (they are per-card
// because the form only has one submit, and cap-field rows are inside
// the card's container — browser sends them in DOM order).
foreach ($capFieldKeys as $fi => $fkey) {
$fkey = trim($fkey);
if ($fkey === '') continue;
$fields[] = [
'key' => $fkey,
'label' => trim($capFieldLbls[$fi] ?? $fkey),
'prompt' => trim($capFieldPrmts[$fi] ?? ''),
];
}
$f['endpoint_key'] = trim($flowCapEps[$i] ?? '');
$f['header'] = trim($flowCapHdrs[$i] ?? '');
$f['success_text'] = trim($flowCapSuccs[$i] ?? '');
$f['confirm'] = !empty($_POST[$confirmKey]);
$f['fields'] = $fields;
}
$flows[$fk] = $f;