feat(bot): add last_7 date_mode y next_endpoint_key para texto+PDF en cadena
- last_7: fecha_desde = hoy-7 días, fecha_hasta = hoy (para ausentismos semana) - next_endpoint_key en executeApiReport: si la primera llamada retorna JSON texto con status=1, envía el texto al usuario y luego ejecuta el endpoint siguiente (ej: produccion_total → texto inmediato + PDF a continuación) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0df08bf953
commit
e3d9aac26d
+16
-1
@@ -1227,6 +1227,9 @@ class NormalBot
|
|||||||
} elseif ($dateMode === 'last_month') {
|
} elseif ($dateMode === 'last_month') {
|
||||||
$extraQuery['fecha_desde'] = date('Y-m-01', strtotime('first day of last month'));
|
$extraQuery['fecha_desde'] = date('Y-m-01', strtotime('first day of last month'));
|
||||||
$extraQuery['fecha_hasta'] = date('Y-m-t', strtotime('last day of last month'));
|
$extraQuery['fecha_hasta'] = date('Y-m-t', strtotime('last day of last month'));
|
||||||
|
} elseif ($dateMode === 'last_7') {
|
||||||
|
$extraQuery['fecha_desde'] = date('Y-m-d', strtotime('-7 days'));
|
||||||
|
$extraQuery['fecha_hasta'] = date('Y-m-d');
|
||||||
}
|
}
|
||||||
$extraQuery['telefono'] = $context['from'];
|
$extraQuery['telefono'] = $context['from'];
|
||||||
$extraQuery['nombre'] = $context['name'] ?? '';
|
$extraQuery['nombre'] = $context['name'] ?? '';
|
||||||
@@ -1268,10 +1271,22 @@ class NormalBot
|
|||||||
return self::sendText('Error al obtener el reporte. Intenta de nuevo.' . $nav, $context['from'], $company);
|
return self::sendText('Error al obtener el reporte. Intenta de nuevo.' . $nav, $context['from'], $company);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si el ERP devuelve JSON (ej: sin_datos), informar al usuario en texto
|
// Si el ERP devuelve JSON (ej: sin_datos o texto), informar al usuario en texto
|
||||||
if (str_starts_with($contentType ?? '', 'application/json')) {
|
if (str_starts_with($contentType ?? '', 'application/json')) {
|
||||||
$json = json_decode($content, true);
|
$json = json_decode($content, true);
|
||||||
$msg = $json['mensaje'] ?? ($json['message'] ?? 'No hay datos disponibles para el período solicitado.');
|
$msg = $json['mensaje'] ?? ($json['message'] ?? 'No hay datos disponibles para el período solicitado.');
|
||||||
|
$nextKey = $params['next_endpoint_key'] ?? '';
|
||||||
|
if ($nextKey !== '' && ($json['status'] ?? '0') === '1') {
|
||||||
|
// Enviar texto primero, luego solicitar el reporte complementario (PDF/Excel)
|
||||||
|
self::sendText($msg, $context['from'], $company);
|
||||||
|
$nextParams = array_merge($params, [
|
||||||
|
'endpoint_key' => $nextKey,
|
||||||
|
'caption' => $params['next_caption'] ?? '',
|
||||||
|
'filename' => $params['next_filename'] ?? 'reporte.pdf',
|
||||||
|
]);
|
||||||
|
unset($nextParams['next_endpoint_key'], $nextParams['next_caption'], $nextParams['next_filename']);
|
||||||
|
return self::executeApiReport($nextParams, $context, $company, $ctxId);
|
||||||
|
}
|
||||||
ConversationContext::reset($ctxId);
|
ConversationContext::reset($ctxId);
|
||||||
return self::sendText('ℹ️ ' . $msg . $nav, $context['from'], $company);
|
return self::sendText('ℹ️ ' . $msg . $nav, $context['from'], $company);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user