From 932a9b43c7e0e2359428eeab5536cc11d77c9480 Mon Sep 17 00:00:00 2001 From: Lizandro Date: Wed, 29 Jul 2026 11:34:46 +0000 Subject: [PATCH] =?UTF-8?q?Saltar=20selecci=C3=B3n=20de=20monto=20si=20el?= =?UTF-8?q?=20cliente=20lo=20incluye=20en=20el=20mensaje=20de=20recarga?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tanto en Telegram como en el chat web, cuando el usuario escribe el monto directamente (ej: "recargar 10.000"), el bot ahora va directo al paso de método de pago sin volver a preguntar el monto. Co-Authored-By: Claude Sonnet 4.6 --- app/Http/Livewire/Chat/PublicChat.php | 15 +++++++++++++-- app/Services/TelegramBotService.php | 13 +++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/Http/Livewire/Chat/PublicChat.php b/app/Http/Livewire/Chat/PublicChat.php index 0014f6b..839e632 100755 --- a/app/Http/Livewire/Chat/PublicChat.php +++ b/app/Http/Livewire/Chat/PublicChat.php @@ -490,7 +490,9 @@ class PublicChat extends Component $action === 'promo.listar' => $this->listarPromociones(), $action === 'promo.ver' => $this->verPromocion((int) ($data['id'] ?? 0)), $action === 'promo.comprar.saldo' => $this->comprarPromoConSaldo((int) ($data['id'] ?? 0)), - $action === 'recarga.iniciar' => $this->mostrarFormRecarga(), + $action === 'recarga.iniciar' => isset($data['monto']) && (int) $data['monto'] >= 1000 + ? $this->elegirMetodoRecarga((int) $data['monto']) + : $this->mostrarFormRecarga(), $action === 'recarga.otro_valor' => $this->solicitarMontoPersonalizado(), $action === 'recarga.elegir_metodo' => $this->elegirMetodoRecarga((int) ($data['monto'] ?? 0)), $action === 'recarga.transferencia' => $this->mostrarTransferencia((int) ($data['monto'] ?? 0)), @@ -1572,7 +1574,16 @@ class PublicChat extends Component foreach ($patrones as $action => $pattern) { if (preg_match($pattern, $t)) { - return ['action' => $action, 'data' => []]; + $data = []; + if ($action === 'recarga.iniciar') { + if (preg_match('/\$?\s*(\d{1,3}(?:[.,]\d{3})+|\d{4,})\b/', $t, $m)) { + $monto = (int) preg_replace('/[.,]/', '', $m[1]); + if ($monto >= 1000) { + $data['monto'] = $monto; + } + } + } + return ['action' => $action, 'data' => $data]; } } diff --git a/app/Services/TelegramBotService.php b/app/Services/TelegramBotService.php index 1da1f35..05a8e24 100755 --- a/app/Services/TelegramBotService.php +++ b/app/Services/TelegramBotService.php @@ -1438,11 +1438,20 @@ class TelegramBotService $texto = $state['data']['last_text'] ?? ''; - // Detección rápida para intents genéricos sin parámetros + // Detección rápida para intents genéricos; extrae monto si viene en el texto if ($texto) { $accionLocal = $this->detectarPorKeywords($texto); if ($accionLocal) { - $this->dispatchAction($chatId, $accionLocal, $state); + $accionData = []; + if ($accionLocal === 'recarga.iniciar') { + if (preg_match('/\$?\s*(\d{1,3}(?:[.,]\d{3})+|\d{4,})\b/', $texto, $m)) { + $monto = (int) preg_replace('/[.,]/', '', $m[1]); + if ($monto >= 1000) { + $accionData['monto'] = $monto; + } + } + } + $this->dispatchAction($chatId, $accionLocal, $state, $accionData); return; } }