fix: show navigation hint after api_report completes or fails

After delivering a report (or on any error), send a text message telling
the user to write "menu" or "salir" so they are never left without guidance.
Also return the hint as a proper response on success (was returning null).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-28 11:43:57 -05:00
co-authored by Claude Sonnet 4.6
parent dee459d53f
commit 0b851208ea
+10 -7
View File
@@ -115,8 +115,11 @@ class NormalBot
private static function executeApiReport(array $params, array $context, array $company, int $ctxId): ?array
{
$endpointKey = $params['endpoint_key'] ?? '';
$nav = "\n\nEscribe *menu* para ver más opciones o *salir* para terminar.";
if ($endpointKey === '') {
return self::sendText('Error: endpoint no configurado.', $context['from'], $company);
ConversationContext::reset($ctxId);
return self::sendText('Error: endpoint no configurado.' . $nav, $context['from'], $company);
}
$stmt = db()->prepare("SELECT url, method FROM company_endpoints WHERE company_id = ? AND endpoint_key = ? AND is_active = 1 LIMIT 1");
@@ -126,7 +129,7 @@ class NormalBot
if (!$ep || empty($ep['url'])) {
self::log("API report: endpoint_key '{$endpointKey}' no configurado para company {$company['id']}");
ConversationContext::reset($ctxId);
return self::sendText('El informe solicitado no está configurado. Contacta al administrador.', $context['from'], $company);
return self::sendText('El informe solicitado no está configurado. Contacta al administrador.' . $nav, $context['from'], $company);
}
$url = $ep['url'];
@@ -172,13 +175,13 @@ class NormalBot
if ($error) {
self::log("API report error [{$endpointKey}]: {$error}");
ConversationContext::reset($ctxId);
return self::sendText('Error al obtener el reporte. Intenta de nuevo.', $context['from'], $company);
return self::sendText('Error al obtener el reporte. Intenta de nuevo.' . $nav, $context['from'], $company);
}
if ($httpCode >= 400) {
self::log("API report HTTP {$httpCode} [{$endpointKey}]: " . mb_substr($content, 0, 200));
ConversationContext::reset($ctxId);
return self::sendText('Error al obtener el reporte. Intenta de nuevo.', $context['from'], $company);
return self::sendText('Error al obtener el reporte. Intenta de nuevo.' . $nav, $context['from'], $company);
}
$mimeMap = [
@@ -212,17 +215,17 @@ class NormalBot
if (!$upload['success'] || !$upload['media_id']) {
self::log("API report upload failed [{$endpointKey}]: " . ($upload['error'] ?? 'unknown'));
ConversationContext::reset($ctxId);
return self::sendText('Error al enviar el reporte. Intenta de nuevo.', $context['from'], $company);
return self::sendText('Error al enviar el reporte. Intenta de nuevo.' . $nav, $context['from'], $company);
}
$reportName = $params['filename'] ?? ('reporte.' . $ext);
$caption = $params['caption'] ?? 'Aquí tienes el reporte solicitado.';
$result = WhatsAppSender::sendDocument($context['from'], $upload['media_id'], $phoneNumberId, $caption, $reportName);
WhatsAppSender::sendDocument($context['from'], $upload['media_id'], $phoneNumberId, $caption, $reportName);
ConversationContext::reset($ctxId);
return null;
return self::sendText('✅ Reporte enviado.' . $nav, $context['from'], $company);
}
private static function buildMenuResponse(array $menu, string $to, array $company): ?array