diff --git a/app/Http/Livewire/Chat/PublicChat.php b/app/Http/Livewire/Chat/PublicChat.php index b8d563d..1a90d67 100755 --- a/app/Http/Livewire/Chat/PublicChat.php +++ b/app/Http/Livewire/Chat/PublicChat.php @@ -212,13 +212,27 @@ class PublicChat extends Component public function limpiarChat(): void { - $this->mensajes = []; - $this->convId = null; - $this->flujo = ''; - $this->flujoData = []; - $this->estadoConv = 'bot'; - session()->forget('chat_conv_id'); - // paso, userId, nombreUsuario, saldoUsuario se mantienen — sesión intacta + $this->flujo = ''; + $this->flujoData = []; + $this->mensajes = []; + + // Crear nueva conversación en lugar de dejar convId en null + if ($this->userId) { + $contact = ChatContact::where('canal', 'web')->where('user_id', $this->userId)->first(); + if ($contact) { + $conv = ChatConversation::create([ + 'contact_id' => $contact->id, + 'canal' => 'web', + 'estado' => 'bot', + 'ultimo_mensaje_at' => now(), + ]); + $this->convId = $conv->id; + $this->estadoConv = 'bot'; + session()->put('chat_conv_id', $conv->id); + $this->mostrarMenuPrincipal($conv->id); + $this->cargarMensajes(); + } + } } public function cerrarSesion(): void