diff --git a/services/NormalBot.php b/services/NormalBot.php index ce97803..acd2787 100644 --- a/services/NormalBot.php +++ b/services/NormalBot.php @@ -1152,7 +1152,9 @@ class NormalBot private static function preservingReset(int $ctxId, array $meta): void { $keep = []; - foreach (['finca'] as $group) { + // grupo_mant se conserva: el submenú de mantenimiento ofrece varios informes + // sobre el mismo grupo, y perderlo dejaba {grupo_id} sin resolver. + foreach (['finca', 'grupo_mant'] as $group) { if (isset($meta[$group])) $keep[$group] = $meta[$group]; } ConversationContext::reset($ctxId); @@ -1287,6 +1289,14 @@ class NormalBot self::substituteUrlVars($ep['url'], array_merge($meta, ['__ep_vars_combined' => $meta['__ep_vars_combined'] ?? []])), $company ); + // Placeholder sin resolver → la API recibiría basura y devolvería un informe + // vacío sin explicación. Mejor pedir el dato que falta. + if (preg_match('/\{(\w+)\}/', $url, $ph)) { + self::log("API report: falta '{$ph[1]}' para [{$endpointKey}] — url: {$url}"); + self::preservingReset($ctxId, ConversationContext::getMetadata($ctxId)); + return self::sendText('Falta seleccionar un dato para generar este informe.' . $nav, $context['from'], $company); + } + $method = strtoupper($ep['method'] ?? 'GET'); $apiKey = $company['api_key'] ?? '';