Files
sirpremiumv2/app/Http/Livewire/Chat/ShowConfiguracionChat.php
T
LizandroandClaude Sonnet 4.6 9b76f63aa0 feat(chat): recarga con transferencia bancaria, fix OTP y mejoras UI
- Fix: autocomplete="off" en campo OTP (evita que el correo aparezca ahí)
- Recarga: nuevo paso elegir método (MercadoPago o Transferencia bancaria)
- Transferencia: muestra card con banco/clave/titular/monto y aviso de comprobante
- Validación automática al enviar foto del comprobante (flujo existente)
- Config admin: nuevos campos banco/clave/titular para transferencia
- UI: card de banco con estilo diferenciado (azul), aviso destacado en ámbar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-14 01:16:51 +00:00

121 lines
4.5 KiB
PHP

<?php
namespace App\Http\Livewire\Chat;
use App\Models\ChatConfig;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Component;
class ShowConfiguracionChat extends Component
{
use LivewireAlert;
// ── Chat general ──────────────────────────────────────────
public string $telegram_token = '';
public string $mensaje_bienvenida = '';
public string $mensaje_transferencia = '';
public string $webhookResult = '';
// ── Gemini IA ─────────────────────────────────────────────
public string $gemini_api_key = '';
public string $gemini_habilitado = '0';
public string $gemini_prompt_extra = '';
// ── Validación de pago por foto + correo ──────────────────
public string $validacion_foto_habilitada = '0';
public string $validacion_accion_auto = 'solo_notificar';
public string $validacion_monto_tolerancia = '0';
// ── Transferencia bancaria ─────────────────────────────────
public string $recarga_banco_nombre = '';
public string $recarga_banco_clave = '';
public string $recarga_banco_titular = '';
public function mount(): void
{
$keys = [
'telegram_token', 'mensaje_bienvenida', 'mensaje_transferencia',
'gemini_api_key', 'gemini_habilitado', 'gemini_prompt_extra',
'validacion_foto_habilitada', 'validacion_accion_auto', 'validacion_monto_tolerancia',
'recarga_banco_nombre', 'recarga_banco_clave', 'recarga_banco_titular',
];
$defaults = [
'mensaje_bienvenida' => 'Hola! Bienvenido. Escribe tu consulta.',
'mensaje_transferencia' => 'Un agente se comunicara contigo en breve. Por favor espera.',
'validacion_accion_auto' => 'solo_notificar',
'validacion_monto_tolerancia' => '0',
];
foreach ($keys as $key) {
$this->{$key} = ChatConfig::get($key, $defaults[$key] ?? '');
}
}
public function guardar(): void
{
$this->validate([
'mensaje_bienvenida' => 'required|string|max:500',
'mensaje_transferencia' => 'required|string|max:500',
'validacion_monto_tolerancia' => 'nullable|integer|min:0',
'recarga_banco_nombre' => 'nullable|max:60',
'recarga_banco_clave' => 'nullable|max:60',
'recarga_banco_titular' => 'nullable|max:100',
]);
$keys = [
'telegram_token', 'mensaje_bienvenida', 'mensaje_transferencia',
'gemini_api_key', 'gemini_habilitado', 'gemini_prompt_extra',
'validacion_foto_habilitada', 'validacion_accion_auto', 'validacion_monto_tolerancia',
'recarga_banco_nombre', 'recarga_banco_clave', 'recarga_banco_titular',
];
foreach ($keys as $key) {
ChatConfig::set($key, $this->{$key});
}
$this->alert('success', 'Configuracion guardada correctamente.');
}
public function registrarWebhook(): void
{
$token = trim($this->telegram_token);
if (! $token) {
$this->webhookResult = 'El token de Telegram esta vacio.';
return;
}
ChatConfig::set('telegram_token', $token);
$webhookUrl = url('/chat/webhook/telegram');
$apiUrl = "https://api.telegram.org/bot{$token}/setWebhook";
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query(['url' => $webhookUrl]),
'timeout' => 10,
],
]);
$result = @file_get_contents($apiUrl, false, $context);
if ($result === false) {
$this->webhookResult = 'Error de conexion con la API de Telegram.';
return;
}
$data = json_decode($result, true);
$this->webhookResult = ($data['ok'] ?? false)
? 'Webhook registrado: ' . ($data['description'] ?? 'OK')
: 'Error: ' . ($data['description'] ?? 'respuesta desconocida');
}
public function render()
{
return view('livewire.chat.show-configuracion-chat');
}
}