feat: custom recharge amount in web chat and Telegram
- Web chat: 'Otro valor' button sets flujo=recarga.monto_custom, next text message is parsed as the amount (min $1.000) - Telegram: '✏️ Otro valor' button sets step=await_amount, next message is parsed and routed to method selection - Preset amounts in Telegram now show 2 per row for compactness Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2fc2aba8a3
commit
a5bac9cee7
@@ -334,6 +334,21 @@ class PublicChat extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
// Capturar monto personalizado de recarga
|
||||
if ($this->flujo === 'recarga.monto_custom') {
|
||||
$monto = (int) preg_replace('/\D/', '', $texto);
|
||||
if ($monto >= 1000) {
|
||||
$this->flujo = '';
|
||||
$this->flujoData = [];
|
||||
$this->elegirMetodoRecarga($monto);
|
||||
} else {
|
||||
$this->guardarMensajeBot($this->convId, "El monto debe ser al menos $1.000. Escríbelo de nuevo:");
|
||||
}
|
||||
$this->cargarMensajes();
|
||||
$this->dispatchBrowserEvent('scroll-chat');
|
||||
return;
|
||||
}
|
||||
|
||||
$accionIA = $this->detectarIntencionIA($texto);
|
||||
|
||||
if ($accionIA) {
|
||||
@@ -369,6 +384,7 @@ class PublicChat extends Component
|
||||
$action === 'promo.comprar.saldo' => $this->comprarPromoConSaldo((int) ($data['id'] ?? 0)),
|
||||
$action === 'promo.comprar.mp' => $this->comprarPromoConMP((int) ($data['id'] ?? 0)),
|
||||
$action === 'recarga.iniciar' => $this->mostrarFormRecarga(),
|
||||
$action === 'recarga.otro_valor' => $this->solicitarMontoPersonalizado(),
|
||||
$action === 'recarga.elegir_metodo' => $this->elegirMetodoRecarga((int) ($data['monto'] ?? 0)),
|
||||
$action === 'recarga.mp' => $this->generarLinkRecargaMP((int) ($data['monto'] ?? 0)),
|
||||
$action === 'recarga.transferencia' => $this->mostrarTransferencia((int) ($data['monto'] ?? 0)),
|
||||
@@ -875,7 +891,8 @@ class PublicChat extends Component
|
||||
foreach ([20000, 50000, 100000, 200000, 500000] as $m) {
|
||||
$botones[] = ['label' => '$' . number_format($m), 'action' => 'recarga.elegir_metodo', 'data' => ['monto' => $m]];
|
||||
}
|
||||
$botones[] = ['label' => 'Volver', 'action' => 'menu.principal', 'data' => []];
|
||||
$botones[] = ['label' => 'Otro valor', 'action' => 'recarga.otro_valor', 'data' => []];
|
||||
$botones[] = ['label' => 'Volver', 'action' => 'menu.principal', 'data' => []];
|
||||
|
||||
ChatMessage::create([
|
||||
'conversation_id' => $this->convId,
|
||||
@@ -887,6 +904,13 @@ class PublicChat extends Component
|
||||
]);
|
||||
}
|
||||
|
||||
private function solicitarMontoPersonalizado(): void
|
||||
{
|
||||
$this->flujo = 'recarga.monto_custom';
|
||||
$this->flujoData = [];
|
||||
$this->guardarMensajeBot($this->convId, "Escribe el monto que deseas recargar (mínimo $1.000):");
|
||||
}
|
||||
|
||||
private function elegirMetodoRecarga(int $monto): void
|
||||
{
|
||||
if ($monto <= 0) {
|
||||
|
||||
@@ -71,12 +71,13 @@ class TelegramBotService
|
||||
$step = $state['step'] ?? 'await_email';
|
||||
|
||||
match ($step) {
|
||||
'await_email' => $this->processEmail($chatId, $text, $nombre),
|
||||
'await_otp' => $this->processOtp($chatId, $text),
|
||||
'await_nombre' => $this->processNombre($chatId, $text),
|
||||
'await_cedula' => $this->processCedula($chatId, $text),
|
||||
'await_celular'=> $this->processCelular($chatId, $text),
|
||||
default => $this->handleFreeText($chatId, $state),
|
||||
'await_email' => $this->processEmail($chatId, $text, $nombre),
|
||||
'await_otp' => $this->processOtp($chatId, $text),
|
||||
'await_nombre' => $this->processNombre($chatId, $text),
|
||||
'await_cedula' => $this->processCedula($chatId, $text),
|
||||
'await_celular' => $this->processCelular($chatId, $text),
|
||||
'await_amount' => $this->processCustomAmount($chatId, $text),
|
||||
default => $this->handleFreeText($chatId, $state),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -107,6 +108,7 @@ class TelegramBotService
|
||||
'promo_saldo' => $this->buyPromoSaldo($chatId, (int) ($parts[1] ?? 0)),
|
||||
'promo_mp' => $this->buyPromoMP($chatId, (int) ($parts[1] ?? 0)),
|
||||
'rec_init' => $this->showRechargeAmounts($chatId),
|
||||
'rec_custom' => $this->askCustomAmount($chatId),
|
||||
'rec_amount' => $this->chooseRechargeMethod($chatId, (int) ($parts[1] ?? 0)),
|
||||
'rec_mp' => $this->rechargeMP($chatId, (int) ($parts[1] ?? 0)),
|
||||
'rec_breb' => $this->rechargeBreb($chatId, (int) ($parts[1] ?? 0)),
|
||||
@@ -729,15 +731,49 @@ class TelegramBotService
|
||||
|
||||
private function showRechargeAmounts(string $chatId): void
|
||||
{
|
||||
$buttons = [];
|
||||
foreach ([20000, 50000, 100000, 200000, 500000] as $m) {
|
||||
$buttons[] = [['text' => '$' . number_format($m), 'callback_data' => 'rec_amount|' . $m]];
|
||||
}
|
||||
$buttons[] = [['text' => '🔙 Menú principal', 'callback_data' => 'menu']];
|
||||
$buttons = [
|
||||
[
|
||||
['text' => '$20.000', 'callback_data' => 'rec_amount|20000'],
|
||||
['text' => '$50.000', 'callback_data' => 'rec_amount|50000'],
|
||||
],
|
||||
[
|
||||
['text' => '$100.000', 'callback_data' => 'rec_amount|100000'],
|
||||
['text' => '$200.000', 'callback_data' => 'rec_amount|200000'],
|
||||
],
|
||||
[
|
||||
['text' => '$500.000', 'callback_data' => 'rec_amount|500000'],
|
||||
['text' => '✏️ Otro valor', 'callback_data' => 'rec_custom'],
|
||||
],
|
||||
[['text' => '🔙 Menú principal', 'callback_data' => 'menu']],
|
||||
];
|
||||
|
||||
$this->sendWithKeyboard($chatId, "💰 *¿Cuánto quieres recargar?*", $buttons);
|
||||
}
|
||||
|
||||
private function askCustomAmount(string $chatId): void
|
||||
{
|
||||
$state = $this->getState($chatId);
|
||||
$state['step'] = 'await_amount';
|
||||
$this->setState($chatId, $state);
|
||||
$this->send($chatId, "Escribe el monto que deseas recargar (mínimo \$1.000):");
|
||||
}
|
||||
|
||||
private function processCustomAmount(string $chatId, string $text): void
|
||||
{
|
||||
$monto = (int) preg_replace('/\D/', '', $text);
|
||||
|
||||
if ($monto < 1000) {
|
||||
$this->send($chatId, "El monto debe ser al menos \$1.000. Escríbelo de nuevo:");
|
||||
return;
|
||||
}
|
||||
|
||||
$state = $this->getState($chatId);
|
||||
$state['step'] = 'menu';
|
||||
$this->setState($chatId, $state);
|
||||
|
||||
$this->chooseRechargeMethod($chatId, $monto);
|
||||
}
|
||||
|
||||
private function chooseRechargeMethod(string $chatId, int $monto): void
|
||||
{
|
||||
if ($monto <= 0) {
|
||||
|
||||
Reference in New Issue
Block a user