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; } }